Skip to content

Commit 8505ab8

Browse files
committed
KVS done
1 parent 4365ccf commit 8505ab8

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/botpress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class botpress {
116116
mkdirIfNeeded(modulesConfigDir, logger)
117117

118118
logger.info(`Starting botpress version ${packageJson.version}`)
119-
119+
120120
const security = createSecurity(dataLocation, botfile.login)
121121

122122
const modules = createModules(logger, projectLocation, dataLocation)

src/database.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Promise from 'bluebird'
22
import moment from 'moment'
3+
34
import helpers from './database_helpers'
5+
import kvs from './kvs'
46

57
const initializeCoreDatabase = knex => {
68
if (!knex) {
@@ -91,9 +93,36 @@ module.exports = ({ sqlite, postgres }) => {
9193
})
9294
}
9395

96+
let kvs_instance = null
97+
const getKvs = () => {
98+
if (!kvs_instance) {
99+
return getDb()
100+
.then(knex => {
101+
kvs_instance = new kvs(knex)
102+
return kvs_instance.bootstrap()
103+
.then(() => kvs_instance)
104+
})
105+
} else {
106+
return Promise.resolve(kvs_instance)
107+
}
108+
}
109+
110+
const kvsGet = function() {
111+
const args = arguments
112+
return getKvs()
113+
.then(instance => instance.get.apply(null, args))
114+
}
115+
116+
const kvsSet = function() {
117+
const args = arguments
118+
return getKvs()
119+
.then(instance => instance.set.apply(null, args))
120+
}
121+
94122
return {
95123
get: getDb,
96124
saveUser,
97-
location: postgres.enabled ? 'postgres' : sqlite.location
125+
location: postgres.enabled ? 'postgres' : sqlite.location,
126+
kvs: { get: kvsGet, set: kvsSet }
98127
}
99128
}

src/kvs.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import _ from 'lodash'
88
and wait for promise to resolve
99
- tableName: overrides the KVS table's name
1010
*/
11-
module.exports = (knex, options) => {
12-
11+
module.exports = (knex, options = {}) => {
1312
const getSetCallback = options.betweenGetAndSetCallback || (() => Promise.resolve())
1413
const tableName = options.tableName || 'kvs'
1514

0 commit comments

Comments
 (0)