@@ -20,12 +20,13 @@ import {
20
20
_mapValues ,
21
21
_Memo ,
22
22
_omit ,
23
- AnyObjectWithId ,
23
+ AnyPartialObjectWithId ,
24
24
CommonLogger ,
25
25
commonLoggerPrefix ,
26
26
JsonSchemaObject ,
27
27
JsonSchemaRootObject ,
28
- ObjectWithId ,
28
+ PartialObjectWithId ,
29
+ Saved ,
29
30
} from '@naturalcycles/js-lib'
30
31
import { ReadableTyped , white } from '@naturalcycles/nodejs-lib'
31
32
import {
@@ -47,7 +48,7 @@ import {
47
48
} from './schema/mysql.schema.util'
48
49
49
50
export interface MysqlDBOptions extends CommonDBOptions { }
50
- export interface MysqlDBSaveOptions < ROW extends Partial < ObjectWithId > = AnyObjectWithId >
51
+ export interface MysqlDBSaveOptions < ROW extends PartialObjectWithId = AnyPartialObjectWithId >
51
52
extends CommonDBSaveOptions < ROW > { }
52
53
53
54
/**
@@ -195,22 +196,22 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
195
196
}
196
197
197
198
// GET
198
- override async getByIds < ROW extends ObjectWithId > (
199
+ override async getByIds < ROW extends PartialObjectWithId > (
199
200
table : string ,
200
- ids : ROW [ 'id' ] [ ] ,
201
+ ids : string [ ] ,
201
202
opt : MysqlDBOptions = { } ,
202
- ) : Promise < ROW [ ] > {
203
+ ) : Promise < Saved < ROW > [ ] > {
203
204
if ( ! ids . length ) return [ ]
204
205
const q = new DBQuery < ROW > ( table ) . filterEq ( 'id' , ids )
205
206
const { rows } = await this . runQuery ( q , opt )
206
207
return rows . map ( r => _mapKeys ( r , k => mapNameFromMySQL ( k as string ) ) as any )
207
208
}
208
209
209
210
// QUERY
210
- override async runQuery < ROW extends ObjectWithId , OUT = ROW > (
211
+ override async runQuery < ROW extends PartialObjectWithId > (
211
212
q : DBQuery < ROW > ,
212
213
_opt : MysqlDBOptions = { } ,
213
- ) : Promise < RunQueryResult < OUT > > {
214
+ ) : Promise < RunQueryResult < Saved < ROW > > > {
214
215
const sql = dbQueryToSQLSelect ( q )
215
216
if ( ! sql ) {
216
217
return {
@@ -260,18 +261,18 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
260
261
}
261
262
}
262
263
263
- override async runQueryCount < ROW extends ObjectWithId > (
264
+ override async runQueryCount < ROW extends PartialObjectWithId > (
264
265
q : DBQuery < ROW > ,
265
266
_opt ?: CommonDBOptions ,
266
267
) : Promise < number > {
267
268
const { rows } = await this . runQuery ( q . select ( [ 'count(*) as _count' as any ] ) )
268
269
return ( rows [ 0 ] as any ) . _count
269
270
}
270
271
271
- override streamQuery < ROW extends ObjectWithId , OUT = ROW > (
272
+ override streamQuery < ROW extends PartialObjectWithId > (
272
273
q : DBQuery < ROW > ,
273
274
_opt : MysqlDBOptions = { } ,
274
- ) : ReadableTyped < OUT > {
275
+ ) : ReadableTyped < Saved < ROW > > {
275
276
const sql = dbQueryToSQLSelect ( q )
276
277
if ( ! sql ) {
277
278
return Readable . from ( [ ] )
@@ -294,7 +295,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
294
295
}
295
296
296
297
// SAVE
297
- override async saveBatch < ROW extends Partial < ObjectWithId > > (
298
+ override async saveBatch < ROW extends PartialObjectWithId > (
298
299
table : string ,
299
300
rowsInput : ROW [ ] ,
300
301
opt : MysqlDBSaveOptions < ROW > = { } ,
@@ -363,11 +364,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
363
364
/**
364
365
* Limitation: always returns [], regardless of which rows are actually deleted
365
366
*/
366
- override async deleteByIds < ROW extends ObjectWithId > (
367
- table : string ,
368
- ids : ROW [ 'id' ] [ ] ,
369
- _opt ?: MysqlDBOptions ,
370
- ) : Promise < number > {
367
+ override async deleteByIds ( table : string , ids : string [ ] , _opt ?: MysqlDBOptions ) : Promise < number > {
371
368
if ( ! ids . length ) return 0
372
369
const sql = dbQueryToSQLDelete ( new DBQuery ( table ) . filterEq ( 'id' , ids ) )
373
370
if ( ! sql ) return 0
@@ -376,7 +373,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
376
373
return affectedRows
377
374
}
378
375
379
- override async deleteByQuery < ROW extends ObjectWithId > (
376
+ override async deleteByQuery < ROW extends PartialObjectWithId > (
380
377
q : DBQuery < ROW > ,
381
378
_opt ?: CommonDBOptions ,
382
379
) : Promise < number > {
@@ -396,7 +393,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
396
393
/**
397
394
* dropIfExists=true needed as a safety check
398
395
*/
399
- override async createTable < ROW extends ObjectWithId > (
396
+ override async createTable < ROW extends PartialObjectWithId > (
400
397
table : string ,
401
398
schema : JsonSchemaObject < ROW > ,
402
399
opt : CommonDBCreateOptions = { } ,
@@ -413,7 +410,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
413
410
. filter ( Boolean )
414
411
}
415
412
416
- override async getTableSchema < ROW extends ObjectWithId > (
413
+ override async getTableSchema < ROW extends PartialObjectWithId > (
417
414
table : string ,
418
415
) : Promise < JsonSchemaRootObject < ROW > > {
419
416
const stats = await this . runSQL < MySQLTableStats [ ] > ( {
@@ -423,7 +420,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
423
420
return mysqlTableStatsToJsonSchemaField < ROW > ( table , stats , this . cfg . logger )
424
421
}
425
422
426
- override async updateByQuery < ROW extends ObjectWithId > (
423
+ override async updateByQuery < ROW extends PartialObjectWithId > (
427
424
q : DBQuery < ROW > ,
428
425
patch : DBPatch < ROW > ,
429
426
) : Promise < number > {
0 commit comments