File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ class botpress {
116
116
mkdirIfNeeded ( modulesConfigDir , logger )
117
117
118
118
logger . info ( `Starting botpress version ${ packageJson . version } ` )
119
-
119
+
120
120
const security = createSecurity ( dataLocation , botfile . login )
121
121
122
122
const modules = createModules ( logger , projectLocation , dataLocation )
Original file line number Diff line number Diff line change 1
1
import Promise from 'bluebird'
2
2
import moment from 'moment'
3
+
3
4
import helpers from './database_helpers'
5
+ import kvs from './kvs'
4
6
5
7
const initializeCoreDatabase = knex => {
6
8
if ( ! knex ) {
@@ -91,9 +93,36 @@ module.exports = ({ sqlite, postgres }) => {
91
93
} )
92
94
}
93
95
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
+
94
122
return {
95
123
get : getDb ,
96
124
saveUser,
97
- location : postgres . enabled ? 'postgres' : sqlite . location
125
+ location : postgres . enabled ? 'postgres' : sqlite . location ,
126
+ kvs : { get : kvsGet , set : kvsSet }
98
127
}
99
128
}
Original file line number Diff line number Diff line change @@ -8,8 +8,7 @@ import _ from 'lodash'
8
8
and wait for promise to resolve
9
9
- tableName: overrides the KVS table's name
10
10
*/
11
- module . exports = ( knex , options ) => {
12
-
11
+ module . exports = ( knex , options = { } ) => {
13
12
const getSetCallback = options . betweenGetAndSetCallback || ( ( ) => Promise . resolve ( ) )
14
13
const tableName = options . tableName || 'kvs'
15
14
You can’t perform that action at this time.
0 commit comments