-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
47 lines (39 loc) · 1.19 KB
/
index.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
40
41
42
43
44
45
46
47
'use strict'
var Knex = require('knex')
var SqlView = require('./build/Release/binding.node')
module.exports = function SsbDb (logPath, dbPath, secretKey, pubKey) {
if (typeof (logPath) !== 'string') {
throw new TypeError('Expected logPath to be a string')
}
if (typeof (dbPath) !== 'string') {
throw new TypeError('Expected dbPath to be a string')
}
if (!Buffer.isBuffer(secretKey)) {
throw new TypeError('Expected secret key to be a buffer. This should be the secret key returned by ssb-keys.')
}
if (typeof (pubKey) !== 'string') {
throw new TypeError('Expected pubKey to be a string')
}
var knex = Knex({
client: 'sqlite3',
useNullAsDefault: true,
connection: {
filename: dbPath
}
})
var db = new SqlView(logPath, dbPath, secretKey, pubKey)
var exports = {
process,
getLatest: () => db.getLatest(),
knex,
modifiers: require('./modifiers').modifiers,
strings: require('./modifiers').strings
}
return exports
function process (opts) {
opts = opts || { chunkSize: -1 }
db.process(opts.chunkSize)
}
}
module.exports.modifiers = require('./modifiers').modifiers
module.exports.strings = require('./modifiers').strings