IceDB
IceDB is a tiny and fast in-memory database for NodeJS
Setup
- Run
npm i -s ice-db
- (optional step) Test the package by running
cd node_modules/ice-db && npm test
Quick Start
- First import the module and instantiate the db .Thats it! Now you're ready to go 🙂
const Ice } = ; const db = ;
- To create a collection:
const animals = db
Now you can call a collection by using variable animals
or db.animals
- To add a new record:
let daisy = animals/*This will return an object like this:{ id: '4e6387b1-ac38-4e42-b474-1c6eaee1302d', rev: '1-1542481509127', type: 'cat', name: 'Daisy' }, but the id and rev would be unique*/
- Records can be accessed by id:
daisy = animals/*{ id: '4e6387b1-ac38-4e42-b474-1c6eaee1302d', rev: '1-1542481509127', type: 'cat', name: 'Daisy' }*/
- To list all records in a collection:
animals;
- To update the record, provide the updated object:
daisytype = 'kitty' let updatedDaisy = animals/*{ id: '6b45e668-698d-4d86-ae4a-bceca15af055', rev: '2-1542482143081', type: 'kitty', name: 'Daisy' }*/
Notice: make sure that the id and rev are there:
let invalid = type: 'cat' name: 'Margaret' try animals catch e console // ID is not defined
let invalid = type: 'cat' name: 'Margaret' id: daisyid try animals catch e console // Rev is not defined
- Delete an object:
animals
- To clear all data in a collection:
animals
or
db
or
db
- You can set a persistent storage for a db:
db // asyncdb // syncdb // this will create a json file with a name of a collection per each containing all data