A wrapper for level
that keeps inserted items ordered.
All items should be in JSON form.
// 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); // []
Returns a promise for all items (+ keys as _id
fields), filtered by a function if provided, in an array form.
Returns a promise for the item matching the key provided.
Returns a promise for the last inserted item.
Asynchronously inserts items provided into the database.
Asynchronously updates an item in the database with the object provided.
Asynchronously deletes an item according to key.
Asynchronously deletes items, filtered by a function if provided.