Skip to content

A wrapper for level that keeps inserted items ordered

License

Notifications You must be signed in to change notification settings

eranbnn/level-ordered

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published