@naturalcycles/mysql-lib 3.14.5 → 3.14.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  import { DBPatch, BaseCommonDB, CommonDB, CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, DBQuery, RunQueryResult, CommonDBSupport, CommonDBType } from '@naturalcycles/db-lib';
2
- import { AnyObjectWithId, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
2
+ import { CommonLogger, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
3
3
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
4
4
  import { Connection, Pool, PoolConfig, PoolConnection, QueryOptions } from 'mysql';
5
5
  export interface MysqlDBOptions extends CommonDBOptions {
6
6
  }
7
- export interface MysqlDBSaveOptions<ROW extends Partial<ObjectWithId> = AnyObjectWithId> extends CommonDBSaveOptions<ROW> {
7
+ export interface MysqlDBSaveOptions<ROW extends ObjectWithId> extends CommonDBSaveOptions<ROW> {
8
8
  }
9
9
  /**
10
10
  * @default false / undefined
@@ -42,8 +42,8 @@ export declare class MysqlDB extends BaseCommonDB implements CommonDB {
42
42
  * Be careful to manage this connection yourself (open, release, etc).
43
43
  */
44
44
  createSingleConnection(): Promise<Connection>;
45
- getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], opt?: MysqlDBOptions): Promise<ROW[]>;
46
- runQuery<ROW extends ObjectWithId, OUT = ROW>(q: DBQuery<ROW>, _opt?: MysqlDBOptions): Promise<RunQueryResult<OUT>>;
45
+ getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: MysqlDBOptions): Promise<ROW[]>;
46
+ runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: MysqlDBOptions): Promise<RunQueryResult<ROW>>;
47
47
  runSQL<RESULT>(q: QueryOptions): Promise<RESULT>;
48
48
  /**
49
49
  * Allows to run semicolon-separated "SQL file".
@@ -51,12 +51,12 @@ export declare class MysqlDB extends BaseCommonDB implements CommonDB {
51
51
  */
52
52
  runSQLString(s: string): Promise<void>;
53
53
  runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
54
- streamQuery<ROW extends ObjectWithId, OUT = ROW>(q: DBQuery<ROW>, _opt?: MysqlDBOptions): ReadableTyped<OUT>;
55
- saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rowsInput: ROW[], opt?: MysqlDBSaveOptions<ROW>): Promise<void>;
54
+ streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: MysqlDBOptions): ReadableTyped<ROW>;
55
+ saveBatch<ROW extends ObjectWithId>(table: string, rowsInput: ROW[], opt?: MysqlDBSaveOptions<ROW>): Promise<void>;
56
56
  /**
57
57
  * Limitation: always returns [], regardless of which rows are actually deleted
58
58
  */
59
- deleteByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], _opt?: MysqlDBOptions): Promise<number>;
59
+ deleteByIds(table: string, ids: string[], _opt?: MysqlDBOptions): Promise<number>;
60
60
  deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
61
61
  /**
62
62
  * Use with caution!
package/package.json CHANGED
@@ -36,7 +36,7 @@
36
36
  "engines": {
37
37
  "node": ">=16.15.0"
38
38
  },
39
- "version": "3.14.5",
39
+ "version": "3.14.7",
40
40
  "description": "MySQL client implementing CommonDB interface",
41
41
  "keywords": [
42
42
  "mysql",
package/src/mysql.db.ts CHANGED
@@ -20,7 +20,6 @@ import {
20
20
  _mapValues,
21
21
  _Memo,
22
22
  _omit,
23
- AnyObjectWithId,
24
23
  CommonLogger,
25
24
  commonLoggerPrefix,
26
25
  JsonSchemaObject,
@@ -47,8 +46,7 @@ import {
47
46
  } from './schema/mysql.schema.util'
48
47
 
49
48
  export interface MysqlDBOptions extends CommonDBOptions {}
50
- export interface MysqlDBSaveOptions<ROW extends Partial<ObjectWithId> = AnyObjectWithId>
51
- extends CommonDBSaveOptions<ROW> {}
49
+ export interface MysqlDBSaveOptions<ROW extends ObjectWithId> extends CommonDBSaveOptions<ROW> {}
52
50
 
53
51
  /**
54
52
  * @default false / undefined
@@ -197,7 +195,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
197
195
  // GET
198
196
  override async getByIds<ROW extends ObjectWithId>(
199
197
  table: string,
200
- ids: ROW['id'][],
198
+ ids: string[],
201
199
  opt: MysqlDBOptions = {},
202
200
  ): Promise<ROW[]> {
203
201
  if (!ids.length) return []
@@ -207,10 +205,10 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
207
205
  }
208
206
 
209
207
  // QUERY
210
- override async runQuery<ROW extends ObjectWithId, OUT = ROW>(
208
+ override async runQuery<ROW extends ObjectWithId>(
211
209
  q: DBQuery<ROW>,
212
210
  _opt: MysqlDBOptions = {},
213
- ): Promise<RunQueryResult<OUT>> {
211
+ ): Promise<RunQueryResult<ROW>> {
214
212
  const sql = dbQueryToSQLSelect(q)
215
213
  if (!sql) {
216
214
  return {
@@ -268,10 +266,10 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
268
266
  return (rows[0] as any)._count
269
267
  }
270
268
 
271
- override streamQuery<ROW extends ObjectWithId, OUT = ROW>(
269
+ override streamQuery<ROW extends ObjectWithId>(
272
270
  q: DBQuery<ROW>,
273
271
  _opt: MysqlDBOptions = {},
274
- ): ReadableTyped<OUT> {
272
+ ): ReadableTyped<ROW> {
275
273
  const sql = dbQueryToSQLSelect(q)
276
274
  if (!sql) {
277
275
  return Readable.from([])
@@ -294,7 +292,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
294
292
  }
295
293
 
296
294
  // SAVE
297
- override async saveBatch<ROW extends Partial<ObjectWithId>>(
295
+ override async saveBatch<ROW extends ObjectWithId>(
298
296
  table: string,
299
297
  rowsInput: ROW[],
300
298
  opt: MysqlDBSaveOptions<ROW> = {},
@@ -363,11 +361,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
363
361
  /**
364
362
  * Limitation: always returns [], regardless of which rows are actually deleted
365
363
  */
366
- override async deleteByIds<ROW extends ObjectWithId>(
367
- table: string,
368
- ids: ROW['id'][],
369
- _opt?: MysqlDBOptions,
370
- ): Promise<number> {
364
+ override async deleteByIds(table: string, ids: string[], _opt?: MysqlDBOptions): Promise<number> {
371
365
  if (!ids.length) return 0
372
366
  const sql = dbQueryToSQLDelete(new DBQuery(table).filterEq('id', ids))
373
367
  if (!sql) return 0
package/src/query.util.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
2
- import { _hb, CommonLogger } from '@naturalcycles/js-lib'
2
+ import { _hb, AnyObjectWithId, CommonLogger } from '@naturalcycles/js-lib'
3
3
  import { white, yellow } from '@naturalcycles/nodejs-lib'
4
4
  import { QueryOptions } from 'mysql'
5
5
  import * as mysql from 'mysql'
@@ -160,7 +160,7 @@ export function dbQueryToSQLUpdate(q: DBQuery<any>, record: Record<any, any>): s
160
160
  return mysql.format(tokens.join(' '), Object.values(record))
161
161
  }
162
162
 
163
- function selectTokens(q: DBQuery): string[] {
163
+ function selectTokens(q: DBQuery<any>): string[] {
164
164
  let fields = ['*']
165
165
 
166
166
  if (q._selectedFieldNames) {
@@ -192,7 +192,7 @@ function offsetLimitTokens(q: DBQuery<any>): string[] {
192
192
  return tokens
193
193
  }
194
194
 
195
- function groupOrderTokens(q: DBQuery): string[] {
195
+ function groupOrderTokens(q: DBQuery<AnyObjectWithId>): string[] {
196
196
  const t: string[] = []
197
197
 
198
198
  if (q._groupByFieldNames?.length) {
@@ -216,7 +216,7 @@ const OP_MAP: Partial<Record<DBQueryFilterOperator, string>> = {
216
216
  /**
217
217
  * Returns `null` for "guaranteed 0 rows" cases.
218
218
  */
219
- function getWhereTokens(q: DBQuery): string[] | null {
219
+ function getWhereTokens(q: DBQuery<any>): string[] | null {
220
220
  if (!q._filters.length) return []
221
221
 
222
222
  let returnNull = false