An (unmaintained) Sophia binding.
Create a db instance at path
.
Open the database, optionally with the given options
.
Options:
createIfMissing
: boolean, default true
readOnly
: boolean, default false
pageSize
: number, default 2048
mergeWatermark
: number, default 100000
yield db.open({ createIfMissing: false });
db.open(function (err) { /* ... */ });
db.openSync();
Close the database.
yield db.close();
db.close(function (err) { /* ... */ });
db.closeSync();
Set key
to value
in the database.
yield db.set('foo', 'bar');
db.set('foo', 'bar', function (err) { /* ... */ });
db.setSync('foo', 'bar');
Get the value of key
.
var value = yield db.get('foo');
db.get('foo', function (err, value) { /* ... */ });
var value = db.getSync('foo');
Delete key
from the database.
var value = yield db.delete('foo');
db.delete('foo', function (err) { /* ... */ });
var value = db.deleteSync('foo');
Create an iterator.
NOTE: Sophia does not support writes while an iterator is open.
Options:
reverse
: boolean, default false
start
: string, default null
end
: string, default null
gte
: boolean, default false
lte
: boolean, default false
Get the next key/value pair from the iterator.
Upon reaching the last key, null
s will be provided.
var arr = yield iterator.next(); // [key, value]
iterator.next(function (err, key, value) { /* ... */ });
End the iterator.
yield iterator.end();
iterator.end(function (err) { /* ... */ });
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.transaction();
var transaction2 = db.transaction(); // throws
Push a set
operation into the transaction.
yield db.set('foo', 'bar');
var transaction = db.transaction();
transaction.set('foo', 'baz');
var val = yield db.get('foo'); // bar
yield transaction.commit();
var val = yield db.get('foo'); // baz
Push a delete
operation into the transaction.
yield db.set('foo', 'bar');
var transaction = db.transaction();
transaction.delete('foo');
var val = yield db.get('foo'); // bar
yield transaction.commit();
var val = yield db.get('foo'); // null
Commit the operations stored by the transaction.
var transaction = db.transaction();
// ...
yield transaction.commit();
transaction.commit(function (err) { /* ... */ });
Rollback/revert the operations stored by the transaction.
var transaction = db.transaction();
// ...
yield transaction.rollback();
transaction.rollback(function (err) { /* ... */ });
MIT