初提交

This commit is contained in:
kangkang520
2018-11-29 14:58:19 +08:00
commit fe2d14c186
10 changed files with 581 additions and 0 deletions

47
README.md Normal file
View File

@ -0,0 +1,47 @@
# 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
```typescript
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()
```