Files
desktop-app/node_modules/db.js
2015-02-27 22:29:38 +08:00

24 lines
766 B
JavaScript

var Datastore = require('nedb');
var path = require('path');
var Evt = require('evt');
// 数据库初始化
// var dbPath = require('nw.gui').App.dataPath + '/nedb';
// var dbPath = Evt.getBasePath() + '/Users/life/Library/Application Support/Leanote' + '/nedb';
var dbPath = Evt.getBasePath() + '/nedb';
// test
if(dbPath.length < 6) {
var dbPath = '/Users/life/Library/Application Support/Leanote' + '/nedb';
}
// console.log(",,,,,,,,,,,,,");
// console.log(dbPath);
var db = {};
var dbNames = ['notebooks', 'notes', 'users', 'tags', 'images', 'attachs', 'noteHistories'];
for(var i in dbNames) {
var name = dbNames[i];
db[name] = new Datastore({ filename: path.join(dbPath, name + '.db'), autoload: true });
}
module.exports = db;
console.log('db init');