kvbox
kvbox provides a simple key/value storage for nodejs. It works by using independent storage adapters. This project was created because keyv sadly doesn't implement the whole Map API.
Features
- Promise based API
- Namespaces
Usage
Install kvbox
npm install kvbox
Create an instance and storage adapter. If no storage adapter is provided default to JavaScripts Map
; ; // store: new Map() await kvbox.set"foo", "bar";await kvbox.get"foo"; // "bar"await kvbox.delete"foo"; // trueawait kvbox.clear; // void
Store
Out of the box kvbox includes a file system adapter, that stores the values in a simple json file. Alternatively you can define your own adapters.
File System Adapter
; ;;
Custom Adapter
You can use any Adatper that implements the Map
Api (without the forEach method).
To write custom adapters you have to extend your adapter with the StorageAdapter
class and implement all required methods.
;
Namespaces
To prevent key collisions when using the same storage adapter, you can declare a namespace
; ;;; await one.set"foo", "one";await two.set"foo", "two"; await one.get"foo"; // "one"await one.delete"foo"; // trueawait two.get"foo"; // "two"
Serializer
By default kvbox uses the flatted JSON parser. You can use your own serializer by declaring it when constructin your Box. This example uses nodejs standard JSON.stringify
and JSON.parse
methods
; ;