@@ -20,7 +20,7 @@ import acl from './plugins/acl.js';
20
20
import waitlist from './plugins/waitlist.js' ;
21
21
import passport from './plugins/passport.js' ;
22
22
import migrations from './plugins/migrations.js' ;
23
- import { SqliteDateColumnsPlugin , connect as connectSqlite } from './utils/sqlite.js' ;
23
+ import { SqliteDateColumnsPlugin , connect as connectSqlite , jsonb } from './utils/sqlite.js' ;
24
24
25
25
const DEFAULT_MONGO_URL = 'mongodb://localhost:27017/uwave' ;
26
26
const DEFAULT_REDIS_URL = 'redis://localhost:6379' ;
@@ -180,6 +180,37 @@ class UwaveServer extends EventEmitter {
180
180
this . redis . quit ( ) ,
181
181
] ) ) ;
182
182
183
+ class KeyValue {
184
+ #db;
185
+
186
+ /** @param {Kysely<import('./schema.js').Database> } db */
187
+ constructor ( db ) {
188
+ this . #db = db ;
189
+ }
190
+
191
+ /** @param {string } key */
192
+ async get ( key , db = this . #db) {
193
+ const row = await db . selectFrom ( 'keyval' )
194
+ . select ( 'value' )
195
+ . where ( 'key' , '=' , key )
196
+ . executeTakeFirst ( ) ;
197
+ return row != null ? JSON . parse ( /** @type {string } */ ( /** @type {unknown } */ ( row . value ) ) ) : null ;
198
+ }
199
+
200
+ /**
201
+ * @param {string } key
202
+ * @param {import('type-fest').JsonValue } value
203
+ */
204
+ async set ( key , value , db = this . #db) {
205
+ await db . insertInto ( 'keyval' )
206
+ . values ( { key, value : jsonb ( value ) } )
207
+ . onConflict ( ( oc ) => oc . column ( 'key' ) . doUpdateSet ( { value : jsonb ( value ) } ) )
208
+ . execute ( ) ;
209
+ }
210
+ }
211
+
212
+ this . keyv = new KeyValue ( this . db ) ;
213
+
183
214
boot . use ( migrations ) ;
184
215
boot . use ( configStore ) ;
185
216
0 commit comments