mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-15 23:55:50 +00:00
数据库迁移到独立表
This commit is contained in:
25
node_modules/db.js
generated
vendored
25
node_modules/db.js
generated
vendored
@@ -20,30 +20,36 @@ var db = {
|
||||
|
||||
// 为全部用户共有的表初始化
|
||||
initGlobal: function () {
|
||||
var me = this;
|
||||
var dbNames = ['users', 'g'];
|
||||
this._init(dbNames);
|
||||
this.initIt(me, dbNames);
|
||||
},
|
||||
|
||||
// 为特定用户初始化自己的表
|
||||
initDBForUser: function (userId) {
|
||||
var me = this;
|
||||
var dbNames = ['notebooks', 'notes', 'tags', 'images', 'attachs', 'noteHistories'];
|
||||
this._init(dbNames, userId);
|
||||
this.initIt(me, dbNames, userId);
|
||||
},
|
||||
|
||||
// 过时
|
||||
init: function () {
|
||||
var me = this;
|
||||
var dbNames = ['users', 'notebooks', 'notes', 'tags', 'images', 'attachs', 'noteHistories', 'g'];
|
||||
this._init(dbNames);
|
||||
this.initIt(me, dbNames);
|
||||
},
|
||||
|
||||
// 过时
|
||||
initForLogin: function () {
|
||||
var me = this;
|
||||
// var dbNames = ['users'];
|
||||
var dbNames = ['users', 'notebooks', 'notes', 'tags', 'noteHistories'];
|
||||
this._init(dbNames);
|
||||
this.initIt(me, dbNames);
|
||||
},
|
||||
|
||||
_init: function (dbNames, userId) {
|
||||
// map, 最后的db设到map里
|
||||
// forceAutoload 是否强制加载
|
||||
initIt: function (map, dbNames, userId, forceAutoload) {
|
||||
var me = this;
|
||||
for(var i in dbNames) {
|
||||
var name = dbNames[i];
|
||||
@@ -60,7 +66,8 @@ var db = {
|
||||
// console.log(dbFilepath);
|
||||
(function (name) {
|
||||
// 这部分非常慢!, 会卡界面
|
||||
me[name] = new Datastore({ filename: dbFilepath, autoload: name != 'noteHistories' , onload: function () {
|
||||
var autoload = forceAutoload || name != 'noteHistories';
|
||||
map[name] = new Datastore({ filename: dbFilepath, autoload: autoload, onload: function () {
|
||||
console.log(userId + '/' + name + ' is loaded');
|
||||
}});
|
||||
})(name);
|
||||
@@ -73,11 +80,13 @@ var db = {
|
||||
Datastore.prototype.loadDB = function(callback) {
|
||||
var me = this;
|
||||
if (this.__loaded) {
|
||||
callback();
|
||||
callback(me.__loadedSuccess);
|
||||
} else {
|
||||
this.loadDatabase(function (err) {
|
||||
me.__loaded = true;
|
||||
callback(err);
|
||||
console.log(err);
|
||||
me.__loadedSuccess = !err;
|
||||
callback(me.__loadedSuccess);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user