Lightweight IndexedDB wrapper
var dex = require('dex')();
// set
dex
.set('foo', 'baz')
.set('baz', 'foo')
.end(function(err, all){});
// get
dex
.get('foo')
.get('baz')
.end(function(err, all){
assert('baz' == all.shift().item.value);
assert('foo' == all.shift().item.value);
});
// del
dex
.del('foo')
.del('baz')
.end(function(err, all){});
// exists
dex
.exists('foo')
.exists('baz')
.end(function(err, bools){});
Install with component(1):
$ component install yields/dex
("connect", event)
("abort", event)
, emitted when a transaction is aborted("complete", event)
, emitted when a transaction is completed("progress", event)
, emitted on transaction progress("set", key, value)
, emitted whenkey
,value
are saved.("del", key)
, emitted when akey
is deleted.
command(name, fn)
is a static method that allows you
to define new commands easily.
all dex()
commands are defined using this method, see examples in lib/commands.js
Create a new Database
instance.
The method is called automatically, you don't need to call
it unless you quit()
.
Disconnect
Set key
, value
with optional fn(err, o)
Get key
's value
.
Determine if a key
exists.
Delete key
Get all keys
that match a regexp
dex().keys(/a/, function(err, keys){});
Abort all running transactions.
var d = dex();
var i = 0;
d.set('multi', 1);
d.set(1, 1);
d.set(2, 2);
d.set(3, 3);
d.get(3);
d.set(4, 4);
d.on('progress', function(e){
if (1 == i++) d.abort();
});
d.end(function(err){
assert(err);
d.get('multi', function(err, o){
if (err) return done(err);
assert(!o.item);
});
});
Invoke the transaction.
dex()
.set('foo', 'baz')
.set('baz', 'foo')
.set('more', { stuff: [] })
.end(function(err, all){});
under the hood dex will create a single transaction of readwrite
.
dex()
.get('foo')
.get('baz')
.get('more')
.end(function(err, all){});
in the above snippet dex()
will create a single readonly
transaction.
dex()
.set('foo', 'foo')
.get('foo')
.set('baz', 'foo')
.set('some', 'stuff')
.del('foo')
.end(function(err, all){});
two transactions will be created readwrite
and readonly
.
$ make test
MIT