-
Notifications
You must be signed in to change notification settings - Fork 2
/
sqlite-db.js
39 lines (29 loc) · 998 Bytes
/
sqlite-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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Db connection retreival for sqlite.
// This class must live in this repo because it used for unit tests.
// This class is also used by the juttle-sqlite-adapter for code-reuse purposes.
'use strict';
let _ = require('underscore');
let Knex = require('knex');
let SqlCommonDB = require('./lib/db');
var REQUIRED_CONFIG_PROPERTIES = ['filename'];
class DB extends SqlCommonDB {
static getKnex(singleDBConfig, options) {
options = options || {};
if (options.db) {
singleDBConfig.filename = options.db;
}
_.each(REQUIRED_CONFIG_PROPERTIES, function(prop) {
if (!singleDBConfig.hasOwnProperty(prop)) {
throw new Error('Each configuration must contain a field: ' + prop);
}
});
var connection = {
filename: singleDBConfig.filename
};
return Knex({
"client": "sqlite3",
"connection": connection
});
}
}
module.exports = DB;