-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
23 lines (20 loc) · 818 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const winston = require('winston');
const config = require('./config');
const sqlite3 = require('sqlite3');
const path = require('path');
const mkdirp = require('mkdirp');
const logger = new winston.Logger(config.logger.winston);
exports.getdb = function(cb) {
//make sure config.sqlite_path basedir exists
mkdirp(path.dirname(config.sqlite_path), (err)=>{
if (err) return cb(err);
var db = new sqlite3.Database(config.sqlite_path);
logger.debug("using db path", config.sqlite_path);
db.serialize(()=>{
db.run("CREATE TABLE IF NOT EXISTS files (path TEXT, mtime INTEGER, tarid INTEGER)");
db.run("CREATE INDEX IF NOT EXISTS files_index ON files (path,mtime)");
db.run("PRAGMA synchronous=OFF");
});
cb(null, db);
});
}