@@ -20,12 +20,13 @@ import {
2020 _mapValues ,
2121 _Memo ,
2222 _omit ,
23- AnyObjectWithId ,
23+ AnyPartialObjectWithId ,
2424 CommonLogger ,
2525 commonLoggerPrefix ,
2626 JsonSchemaObject ,
2727 JsonSchemaRootObject ,
28- ObjectWithId ,
28+ PartialObjectWithId ,
29+ Saved ,
2930} from '@naturalcycles/js-lib'
3031import { ReadableTyped , white } from '@naturalcycles/nodejs-lib'
3132import {
@@ -47,7 +48,7 @@ import {
4748} from './schema/mysql.schema.util'
4849
4950export interface MysqlDBOptions extends CommonDBOptions { }
50- export interface MysqlDBSaveOptions < ROW extends Partial < ObjectWithId > = AnyObjectWithId >
51+ export interface MysqlDBSaveOptions < ROW extends PartialObjectWithId = AnyPartialObjectWithId >
5152 extends CommonDBSaveOptions < ROW > { }
5253
5354/**
@@ -195,22 +196,22 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
195196 }
196197
197198 // GET
198- override async getByIds < ROW extends ObjectWithId > (
199+ override async getByIds < ROW extends PartialObjectWithId > (
199200 table : string ,
200- ids : ROW [ 'id' ] [ ] ,
201+ ids : string [ ] ,
201202 opt : MysqlDBOptions = { } ,
202- ) : Promise < ROW [ ] > {
203+ ) : Promise < Saved < ROW > [ ] > {
203204 if ( ! ids . length ) return [ ]
204205 const q = new DBQuery < ROW > ( table ) . filterEq ( 'id' , ids )
205206 const { rows } = await this . runQuery ( q , opt )
206207 return rows . map ( r => _mapKeys ( r , k => mapNameFromMySQL ( k as string ) ) as any )
207208 }
208209
209210 // QUERY
210- override async runQuery < ROW extends ObjectWithId , OUT = ROW > (
211+ override async runQuery < ROW extends PartialObjectWithId > (
211212 q : DBQuery < ROW > ,
212213 _opt : MysqlDBOptions = { } ,
213- ) : Promise < RunQueryResult < OUT > > {
214+ ) : Promise < RunQueryResult < Saved < ROW > > > {
214215 const sql = dbQueryToSQLSelect ( q )
215216 if ( ! sql ) {
216217 return {
@@ -260,18 +261,18 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
260261 }
261262 }
262263
263- override async runQueryCount < ROW extends ObjectWithId > (
264+ override async runQueryCount < ROW extends PartialObjectWithId > (
264265 q : DBQuery < ROW > ,
265266 _opt ?: CommonDBOptions ,
266267 ) : Promise < number > {
267268 const { rows } = await this . runQuery ( q . select ( [ 'count(*) as _count' as any ] ) )
268269 return ( rows [ 0 ] as any ) . _count
269270 }
270271
271- override streamQuery < ROW extends ObjectWithId , OUT = ROW > (
272+ override streamQuery < ROW extends PartialObjectWithId > (
272273 q : DBQuery < ROW > ,
273274 _opt : MysqlDBOptions = { } ,
274- ) : ReadableTyped < OUT > {
275+ ) : ReadableTyped < Saved < ROW > > {
275276 const sql = dbQueryToSQLSelect ( q )
276277 if ( ! sql ) {
277278 return Readable . from ( [ ] )
@@ -294,7 +295,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
294295 }
295296
296297 // SAVE
297- override async saveBatch < ROW extends Partial < ObjectWithId > > (
298+ override async saveBatch < ROW extends PartialObjectWithId > (
298299 table : string ,
299300 rowsInput : ROW [ ] ,
300301 opt : MysqlDBSaveOptions < ROW > = { } ,
@@ -363,11 +364,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
363364 /**
364365 * Limitation: always returns [], regardless of which rows are actually deleted
365366 */
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 > {
371368 if ( ! ids . length ) return 0
372369 const sql = dbQueryToSQLDelete ( new DBQuery ( table ) . filterEq ( 'id' , ids ) )
373370 if ( ! sql ) return 0
@@ -376,7 +373,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
376373 return affectedRows
377374 }
378375
379- override async deleteByQuery < ROW extends ObjectWithId > (
376+ override async deleteByQuery < ROW extends PartialObjectWithId > (
380377 q : DBQuery < ROW > ,
381378 _opt ?: CommonDBOptions ,
382379 ) : Promise < number > {
@@ -396,7 +393,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
396393 /**
397394 * dropIfExists=true needed as a safety check
398395 */
399- override async createTable < ROW extends ObjectWithId > (
396+ override async createTable < ROW extends PartialObjectWithId > (
400397 table : string ,
401398 schema : JsonSchemaObject < ROW > ,
402399 opt : CommonDBCreateOptions = { } ,
@@ -413,7 +410,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
413410 . filter ( Boolean )
414411 }
415412
416- override async getTableSchema < ROW extends ObjectWithId > (
413+ override async getTableSchema < ROW extends PartialObjectWithId > (
417414 table : string ,
418415 ) : Promise < JsonSchemaRootObject < ROW > > {
419416 const stats = await this . runSQL < MySQLTableStats [ ] > ( {
@@ -423,7 +420,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
423420 return mysqlTableStatsToJsonSchemaField < ROW > ( table , stats , this . cfg . logger )
424421 }
425422
426- override async updateByQuery < ROW extends ObjectWithId > (
423+ override async updateByQuery < ROW extends PartialObjectWithId > (
427424 q : DBQuery < ROW > ,
428425 patch : DBPatch < ROW > ,
429426 ) : Promise < number > {
0 commit comments