[UPDATE] I later found out some example:
this.db = new Loki("viewsaving", {
autosave: true,
autosaveInterval: 5000,
autoload: true,
autoloadCallback: function(){
db_ready = true;
if(db.getCollection("namedviews") == null ){
this.namedviews = db.addCollection("namedviews");
}
if(db.getCollection("timedviews") == null ){
this.timedviews = db.addCollection("timedviews");
}
}
});
It basically works on my side. so I just use it, not sure if this is correct or not, please report.
Everything:
I'm new to Lokijs, I wonder how can I reload the database and collection that were saved?
Let's say that I create a database and a collection and then save it (for example, click a button to invoke the save process):
var db = new Loki("mydb");
var users = db.addCollection('users');
function saveUser(){
users.insert({
name: 'joe'
});
users.insert({
name: 'john'
});
users.insert({
name: 'jack'
});
db.saveDatabase();
}
Then, when I refresh this page, how can I load "mydb" and "users" from persistence and not create a new one (since it will go through again var db = new Loki("mydb");), is there an API to check for the presence of a database?
thanks