JSFiddle - React, Tailwind, and code Playground

by darknessm0404

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lokijs/1.5.0/lokijs.min.js"></script>

JavaScript

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; })