1.3.0 • Published 5 years ago
cocodb v1.3.0
CocoDB
Getting started
1. Create a new CocoDB instance
const { CocoDB, LocalStorage } = require('cocodb')
const db = new CocoDB({
storage: LocalStorage, // optional
storageName: '__localdb' // optional
})
// u can add a Storage
db.setStorage({
storage: LocalStorage, // optional
storageName: '__localdb' // optional
})
2. You can use the following methods
2.1. Add elements
await db.add({
name: 'Wilson',
age: 12
})
// or add multiple
await db.addMany([
{
name: 'Wilson',
age: 44
},
{
name: 'Zon',
age: 25
}
])
2.2. Find elements
// using id
await db.findById('123')
// using a query object
// u can use a function, too. See: https://lodash.com/docs/#find
await db.find({
name: 'Wilson'
})
2.3. Remove element
// using id
await db.remove('123')
2.4. Sort elements
await db.sortBy(['_id', 'name'])
// or
await db.sortBy(function(o) {
return o.name
})
// see: https://lodash.com/docs/#sortBy
2.4. Save, restore and remove / Storage
// save the data to the storage
await db.save()
// restore data from the storage
await db.restore()
// remove data from the storage
await db.delete()