0
我想爲我的AngularJS v1應用使用LokiJS。我認爲編寫自己的持久化工廠是個好主意,這樣我就可以很容易地更改數據庫系統。在我的Angular 1應用程序中使用LokiJS的最佳方式是什麼?
LokiJS對Angular(loki-angular.js)有特殊的實現,並且包含一個Lokiwork服務。
你會怎麼做?使用Lokiwork,還是更好的我自己的系統?
謝謝, 基督徒。
我想爲我的AngularJS v1應用使用LokiJS。我認爲編寫自己的持久化工廠是個好主意,這樣我就可以很容易地更改數據庫系統。在我的Angular 1應用程序中使用LokiJS的最佳方式是什麼?
LokiJS對Angular(loki-angular.js)有特殊的實現,並且包含一個Lokiwork服務。
你會怎麼做?使用Lokiwork,還是更好的我自己的系統?
謝謝, 基督徒。
您可以在loki初始化時創建一個工廠,並且在同一工廠中,您可以編寫創建表的方法,填充表,從表中檢索數據。
通過這樣做你所有與數據庫相關的代碼在同一個地方。
下面是你可以在你的應用程序中實現lokijs的一些事情。
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;
}]);
有些東西可以在您的應用程序中實現。
希望這可以幫助你。