You can create a factory when the loki is initialized, and also in the same factory you can write methods to create a table, populate the table, retrieve the data from the table.
By doing this all you DB related code is in one place.
Below is some thing which you can do to implement lokijs in your application.
app.factory('InAppStorageUtility', ['Loki', function (Loki) {
var db = {
initilizeLoki: function() {
var thisScope = this;
var inappDb = new loki("DBName", { autosave: false });
inappDb.loadDatabase({}, function () {
var tableInititalized = offlineDb.getCollection('testTable');
if (tableInititalized === null) {
thisScope.createTables();
}
});
},
createTables: function() {
// Table creation logic. Give a structure of the table
// var tableCreation = offlineDb.addCollection('testTable');
// Provide the table structure
},
insertValuesToTable: function() {
// Insert logic for all you tables
},
getValuesStoredInDB: function() {
// Retrieving values from the DB logic goes here.
// var getTableValue = offlineDb.getCollection('testTable');
}
}
return db;
}]);
Some thing like this you can implement in your application.
Hope this helps you.