项目作者: eranbnn

项目描述 :
A wrapper for level that keeps inserted items ordered
高级语言: JavaScript
项目地址: git://github.com/eranbnn/level-ordered.git
创建时间: 2020-09-13T13:45:51Z
项目社区:https://github.com/eranbnn/level-ordered

开源协议:MIT License

下载


level-ordered

A wrapper for level that keeps inserted items ordered.

npm
npm

All items should be in JSON form.

Usage

  1. // create/access database
  2. const testDB = await Database.access('dbName', 'collectionName');
  3. // insert items
  4. await testDB.insert({ val: 'one' }, { val: 'two' }, { val: 'three' });
  5. // get all items
  6. const allItems = await testDB.getAll();
  7. allItems.map(({ val }) => val); // ['one', 'two', 'three']
  8. // get last item
  9. await testDB.getLastItem(); // { val: 'three' }
  10. // delete item: { val: 'two' }
  11. const filterFunc = ({ val }) => val === 'two';
  12. await testDB.deleteBy(filterFunc);
  13. await testDB.getAll(filterFunc); // []

API

getAll([filterFunc])

Returns a promise for all items (+ keys as _id fields), filtered by a function if provided, in an array form.

getKey(key)

Returns a promise for the item matching the key provided.

getLastItem()

Returns a promise for the last inserted item.

insert(...newItems)

Asynchronously inserts items provided into the database.

update(key, updateObj)

Asynchronously updates an item in the database with the object provided.

deleteKey(key)

Asynchronously deletes an item according to key.

deleteBy([filterFunc])

Asynchronously deletes items, filtered by a function if provided.

License

MIT