0.0.1 • Published 7 years ago

kvstorage v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

kvstorage

!! work in progress !!

When a database is opened, all key/values are read from the logfiles into memory.

Keys and values must be strings. They are stored only if the value contains at least one character. The get() method returns the empty string for non-existing keys. Keys and values may not contain control characters (0x00...0x1F, 0x7F, 0x80...0x9F, U+2028, U+2029). The equal sign ('=') is also forbidden for keys.

Logfiles are write-once. Data is written only to the current logfile. Older logfiles will not be modified, but they may be deleted when they are no longer needed. Logfiles are pure UTF-8 text files.

There is no file locking! Make sure that you don't open the database twice at the same time.

API

get the package

const KVStorage = require("kvstorage");

create the database handle

const db = new KVStorage("/tmp/kvdb/");

The directory must exist before the KVStorage() is created.

load the database

promisified

db.open().then(___).catch(___);

with traditional callback

db.open((err) => ___);

get a value

var value = db.get(key);

This method returns the empty string for non-existing keys.

set a key/value

db.set(key, value);

Throws an Error if the key or value contain illegal characters.

delete a key

To delete a key just call set() with an empty string.

db.set(key);
db.set(key, "");
db.set(key, null);
db.set(key, undefined);

commit changes

promisified

db.commit().then(___).catch(___);

with traditional callback

db.commit((err) => ___);

abort changes

db.abort()

close the database

db.close()

•••