Streamable database adapter for LokiJS, an in-memory JavaScript database. This library also pairs nicely with crudlet, along with all the other crudlet plugins such as crudlet-pubnub, and crudlet-http.
var crud = ;var lokidb = ;var loki = ;var _ = ; // setup the DBvar db = ;// db = lokidb(__dirname + "/db.json"); // also works // setup the child collectionvar peopleDb = crud; // insert one, or many items
db lokidb(targetOrOptions)
Creates a new crudlet-based db
targetOrOptions
- the target loki DB or the options for a new loki db
var db = ;var db = ;
db(operationName, options)
Runs a new operation on the loki DB.
Note that
options.collection
must be present when performing operations. The easiest & probably best way to do this is to create achild
crudlet db.
// remove all people where ages are greater than zero;
insert
Insert operation.
var peopleDb = crud; // insert multiple;
update
Update operation
;
upsert
Updates a document if it's found, or inserts one.
;
remove
Removes a document
;
load
Removes a document
;
Interoperability with other database
crudlet-loki
works well with other crudlet adapters. Below are a some examples of
what you can do.
Realtime data
Use whatever realtime adapter you want - pubnub, webrtc, socket.io. Here's an example with pubnub:
var pubnub = ;var loki = ;var crud = ; var remotedb = ; // tailable makes "tail" an option for databases that don't support it (such as lokidb).// "tail" gets emmited whenever there's an operation executed against the databasevar memdb = crud; // tail all remote operations to the memory database; // tail operations on the in-memory database & pass them back to pubnub// NOTE that operations coming from pubnub won't get re-published.; // insert data to the local database - this will also get sent to pubnub;