cluster-memdb
v1.0.4
Published
key-value memory database for single process application and cluster application
Downloads
3
Maintainers
Readme
cluster-memdb
A key-value memory database for single process application and cluster application.
Using this util, you can share datas in every processes of cluster.
installation
npm install cluster-memdb
usage
this example show you how to use it, you can read .d.ts
for more information
import {memdb, dbs} from 'cluster-memdb'
// declare database (won't create any keys)
const userdb = memdb('user', 'id')
const lovedb = memdb('love', 'key')
// create "user" key and write those 2 users to "user"
await userdb.save([
{id:1, name:'Mike', gender:'male', love:['bread']},
{id:2, name:'Louis', gender:'female', love:['beef', 'bread']},
])
// clean "love" key and write new datas
await lovedb.replace([
{key:'bread', price:'3.00'},
{key:'beef', price:'10.00'}
])
await dbs() // ["user", "love"]
await userdb.getAll() // [{id:1, ...}, {id:2, ...}]
await lovedb.getByKeys(['bread']) // [{key:'bread', price:'3.00'}]
await userdb.find({name:'Mike'}) // [{id:1, ...}]
// "Mike" and "Louis" both deleted
await userdb.delete([1, 2])
// "bread" and "beef" both deleted
await love.clean()