1

I am using framework7 with lokijs. To use lokijs database, i need to create new database everytime with new loki(dbname)

how do i create a database on my first run and from next runs just load that database ?

2 Answers2

1

To create new database (each run this code will clear your data in file mydb.json):

var loki = require('lokijs');
var db = new loki('mydb.json');
var users = db.addCollection('users');//create users collection in file mydb.json
db.saveDatabase();//save file

To work with file

var loki = require('lokijs');
var db = new loki('mydb.json);
var users = db.getCollection('users');
users.insert({name: 'User', age: 20}); //add user with name User and age 20
users.removeWhere({age: 20}); //delete all users where age = 20
//something else
db.saveDatabase(); //save changes to file

also you can read docs

Pavel
  • 11
  • 1
0

I think the wiki is a good place to start for your issue. LokiJS can load an existing database with the loadDatabase() method.

Joe Minichino
  • 2,793
  • 20
  • 20