node-leveled
A js-style LevelDB binding for node.
The datatype is plain strings, support for buffers and other formats may be added.
Usage
var db = '/tmp/mydb'; db db db db
Installation
$ npm install leveled
API
leveled(path)
Instantiates a new DB at path
, creating path
if necessary.
leveled#put(key, val[, cb])
leveled#putSync(key, val)
Store val
at key
.
leveled#get(key, cb)
leveled#getSync(key)
Get the value stored at key
.
leveled#del(key[, cb])
leveled#delSync(key)
Delete the value stored at key
.
leveled#range(from, to, cb)
Find all entries whose keys are in the give range.
from
can befrom
/[from
or(from
to
can beto
/to]
orto)
db
leveled#find(glob, cb)
Find values.
db
At the moment glob-style matching is not fully implemented, what works is
abc*
*
In the future it will work like redis's KEYS
command:
ab?
matchesabc
, notabcc
ab[1-3]
matchesab1
,ab2
,ab3
ab[1-3]*
etc.
leveled#batch()
Creates a new batch
that queues up operations until its write
method is invoked.
batch#put(key, val)
batch#del(key)
batch#write(cb)
batch#writeSync()
Apply the batch's operations to the DB.
Benchmark
On my mb pro:
$ node bench/bench.js benchmarking with 120,000 records, 24 chars each put : 128,479 w/s in 934ms putSync : 372,670 w/s in 322ms batch : 612,244 w/s in 196ms batchSync : 641,711 w/s in 187ms get : 58,881 r/s in 2,038ms getSync : 560,747 r/s in 214ms iterator : 220,588 r/s in 544ms
put
oparations don't force a sync to disk, hence the get
looking so slow. Iterators are faster for common tasks where you need to get many values anyways.
TODO
- evaluate leveldb::Slice for storage
- evaluate buffers as data type
- evaluate storing native js objects
- evaluate msgpack
License
(MIT)