sophist
A (maintained) Sophia binding.
API
var db = new Sophist(path);
Create a db instance at path
.
db.open([options], [fn]) / db.openSync([options])
Open the database, optionally with the given options
.
Options:
createIfMissing
: boolean, defaulttrue
readOnly
: boolean, defaultfalse
pageSize
: number, default2048
mergeWatermark
: number, default100000
db;db;db;
db.close([fn]) / db.closeSync()
Close the database.
db;db;db;
db.set(key, value, [fn]) / db.setSync(key, value)
Set key
to value
in the database.
db;db;db;
db.get(key, [fn]) / db.getSync(key)
Get the value of key
.
var value = db;db;var value = db;
db.delete(key, [fn]) / db.deleteSync(key)
Delete key
from the database.
var value = db;db;var value = db;
var iterator = db.iterator([options])
Create an iterator.
NOTE: Sophia does not support writes while an iterator is open.
Options:
reverse
: boolean, defaultfalse
start
: string, defaultnull
end
: string, defaultnull
gte
: boolean, defaultfalse
lte
: boolean, defaultfalse
iterator.next([fn])
Get the next key/value pair from the iterator.
Upon reaching the last key, null
s will be provided.
var arr = iteratornext; // [key, value]iteratornext { /* ... */ };
iterator.end([fn])
End the iterator.
iterator;iterator;
var transaction = db.transaction()
Create a Sophia transaction.
During a transaction, all writes (set
and delete
) are posponed until transaction#commit()
is called. Transaction writes may be reverted by calling transaction#rollback()
.
Unlike Sophia's raw C API, values set by transaction#set()
and transaction#get()
are not able to be retreived by sophist#get()
.
Sophia does not support nested or multiple transactions, so doing so will cause an error to be thrown.
var transaction = db;var transaction2 = db; // throws
transaction.set(key, value)
Push a set
operation into the transaction.
db;var transaction = db;transaction;var val = db; // bar transaction;var val = db; // baz
transaction.delete(key)
Push a delete
operation into the transaction.
db;var transaction = db;transaction;var val = db; // bar transaction;var val = db; // null
transaction.commit([fn])
Commit the operations stored by the transaction.
var transaction = db;// ... transaction;transaction;
transaction.rollback([fn])
Rollback/revert the operations stored by the transaction.
var transaction = db;// ... transaction;transaction;
License
MIT