@neykoor/keyed-db
v1.0.0
Published
Lightweight library to store an in-memory DB, trimmed fork for BaileysX
Readme
Keyed DB
A light-weight node library to manage a sorted & indexed collection.
Trimmed ESM fork of @adiwajshing/keyed-db for use in BaileysX, keeping only
the methods actually used there.
Install
npm i @neykoor/keyed-db
Functions
db = new KeyedDB<T> (t => t.uniqueNumberKeyProperty, t => t.optionalUniqueIDProperty)
db = new KeyedDB<T> ({
key: t => t.someProperty,
compare: (t1, t2) => someComputation(t1, t2)
}, t => t.optionalUniqueIDProperty)
db.insert (value)
db.upsert (value)
db.insertIfAbsent (value)
db.delete (value)
db.deleteById (value.optionalUniqueIDProperty)
db.update (id, value => value.someProperty = newValue)
db.get (id)
db.filter (predicate)
db.all ()
db.clear ()
Usage
import KeyedDB from '@neykoor/keyed-db'
type Chat = {
timestamp: Date
chatID: string
}
const db = new KeyedDB<Chat>(value => value.timestamp.getTime()*-1, value => value.chatID)
db.insert (
{
timestamp: new Date(),
chatID: `person 1`
}
)