level-ordered
v3.0.0
Published
a wrapper for level database that keeps order
Downloads
6
Maintainers
Readme
level-ordered
A wrapper for level
that keeps inserted items ordered.
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.