level-ordered

3.0.0 • Public • Published

level-ordered

A wrapper for level that keeps inserted items ordered.

npm npm

All items should be in JSON form.

Usage

// create/access database
const testDB = await Database.access('dbName', 'collectionName');
 
// insert items
await testDB.insert({ val: 'one' }, { val: 'two' }, { val: 'three' });
 
// get all items
const allItems = await testDB.getAll();
allItems.map(({ val }) => val); // ['one', 'two', 'three']
 
// get last item
await testDB.getLastItem(); // { val: 'three' }
 
// delete item: { val: 'two' }
const filterFunc = ({ val }) => val === 'two';
await testDB.deleteBy(filterFunc);
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

Dependents (0)

Package Sidebar

Install

npm i level-ordered

Weekly Downloads

2

Version

3.0.0

License

MIT

Unpacked Size

11 kB

Total Files

5

Last publish

Collaborators

  • eranbnn