function MyCustomAdapter() {
this.mode = "reference";
}
MyCustomAdapter.prototype.loadDatabase = function(dbname, callback) {
// using dbname, load the database from wherever your adapter expects it
var serializedDb = localStorage[dbname];
var success = true; // make your own determinations
if (success) {
callback(serializedDb);
}
else {
callback(new Error("There was a problem loading the database"));
}
}
MyCustomAdapter.prototype.saveDatabase = function(dbname, dbstring, callback) {
// store the database, for this example to localstorage
localStorage[dbname] = dbstring;
debugger;
var success = true; // make your own determinations
if (success) {
callback(null);
}
else {
callback(new Error("An error was encountered loading " + dbname + " database."));
}
}
var instAdapter = new MyCustomAdapter();
var db = new loki("test", {
autosave: false,
adapter: instAdapter
});
var jsonToImport = {
"collections":[
{
"name":"documents",
"data":[
{
someData:'random',
doc: {type:'bir1', _id:'1234', creationDate: new Date()}
},
{
someData:'random2',
doc: {type:'bir1', _id:'456', creationDate: new Date()}
}
]
}
]
};
db.loadJSONObject(jsonToImport);
var documents = db.getCollection('documents');
var searchList = ['1234', '12345'];
var testresult = documents.find({'doc._id': { $in: searchList} });
console.log(testresult);
/*
var documents = db.addCollection('documents');
documents.insert({type:'bir1', _id:'1234', creationDate: new Date()});
documents.insert({type:'bir1', _id:'12345', creationDate: new Date()});
*/
//db.saveDatabase(function (r){ debugger; })
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.