@naturalcycles/mysql-lib 3.16.1 → 3.16.2

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,6 +1,5 @@
1
- import { CommonDBCreateOptions, CommonKeyValueDB } from '@naturalcycles/db-lib';
1
+ import { CommonDBCreateOptions, CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
2
  import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB';
3
- import { KeyValueTuple } from '@naturalcycles/js-lib';
4
3
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
5
4
  import { MysqlDB, MysqlDBCfg } from './mysql.db';
6
5
  export declare class MySQLKeyValueDB implements CommonKeyValueDB {
@@ -14,19 +13,18 @@ export declare class MySQLKeyValueDB implements CommonKeyValueDB {
14
13
  ping(): Promise<void>;
15
14
  close(): Promise<void>;
16
15
  createTable(table: string, opt?: CommonDBCreateOptions): Promise<void>;
17
- getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]>;
16
+ getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]>;
18
17
  /**
19
18
  * Use with caution!
20
19
  */
21
20
  dropTable(table: string): Promise<void>;
22
21
  deleteByIds(table: string, ids: string[]): Promise<void>;
23
- saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void>;
22
+ saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void>;
24
23
  streamIds(table: string, limit?: number): ReadableTyped<string>;
25
- streamValues<V>(table: string, limit?: number): ReadableTyped<V>;
26
- streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>>;
24
+ streamValues(table: string, limit?: number): ReadableTyped<Buffer>;
25
+ streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple>;
27
26
  beginTransaction(): Promise<void>;
28
27
  endTransaction(): Promise<void>;
29
28
  count(table: string): Promise<number>;
30
- increment(_table: string, _id: string, _by?: number): Promise<number>;
31
29
  incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]>;
32
30
  }
@@ -101,9 +101,6 @@ class MySQLKeyValueDB {
101
101
  const rows = await this.db.runSQL({ sql });
102
102
  return rows[0].cnt;
103
103
  }
104
- async increment(_table, _id, _by) {
105
- throw new js_lib_1.AppError('MySQLKeyValueDB.increment() is not implemented');
106
- }
107
104
  async incrementBatch(_table, _entries) {
108
105
  throw new js_lib_1.AppError('MySQLKeyValueDB.incrementBatch() is not implemented');
109
106
  }
package/package.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "engines": {
42
42
  "node": ">=20.13.0"
43
43
  },
44
- "version": "3.16.1",
44
+ "version": "3.16.2",
45
45
  "description": "MySQL client implementing CommonDB interface",
46
46
  "keywords": [
47
47
  "mysql",
@@ -2,16 +2,17 @@ import {
2
2
  CommonDBCreateOptions,
3
3
  CommonKeyValueDB,
4
4
  commonKeyValueDBFullSupport,
5
+ KeyValueDBTuple,
5
6
  } from '@naturalcycles/db-lib'
6
7
  import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB'
7
- import { AppError, KeyValueTuple, ObjectWithId, pMap } from '@naturalcycles/js-lib'
8
+ import { AppError, ObjectWithId, pMap } from '@naturalcycles/js-lib'
8
9
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'
9
10
  import { QueryOptions } from 'mysql'
10
11
  import { MysqlDB, MysqlDBCfg } from './mysql.db'
11
12
 
12
- interface KeyValueObject<V> {
13
+ interface KeyValueObject {
13
14
  id: string
14
- v: V
15
+ v: Buffer
15
16
  }
16
17
 
17
18
  export class MySQLKeyValueDB implements CommonKeyValueDB {
@@ -45,12 +46,12 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
45
46
  await this.db.runSQL({ sql })
46
47
  }
47
48
 
48
- async getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]> {
49
+ async getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]> {
49
50
  if (!ids.length) return []
50
51
 
51
52
  const sql = `SELECT id,v FROM ${table} where id in (${ids.map(id => `"${id}"`).join(',')})`
52
53
 
53
- const rows = await this.db.runSQL<KeyValueObject<V>[]>({ sql })
54
+ const rows = await this.db.runSQL<KeyValueObject[]>({ sql })
54
55
 
55
56
  return rows.map(({ id, v }) => [id, v])
56
57
  }
@@ -68,7 +69,7 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
68
69
  await this.db.runSQL({ sql })
69
70
  }
70
71
 
71
- async saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void> {
72
+ async saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void> {
72
73
  const statements: QueryOptions[] = entries.map(([id, buf]) => {
73
74
  return {
74
75
  sql: `INSERT INTO ${table} (id, v) VALUES (?, ?)`,
@@ -90,20 +91,20 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
90
91
  return (this.db.pool().query(sql).stream() as ReadableTyped<ObjectWithId>).map(row => row.id)
91
92
  }
92
93
 
93
- streamValues<V>(table: string, limit?: number): ReadableTyped<V> {
94
+ streamValues(table: string, limit?: number): ReadableTyped<Buffer> {
94
95
  let sql = `SELECT v FROM ${table}`
95
96
  if (limit) sql += ` LIMIT ${limit}`
96
97
  if (this.cfg.logSQL) this.db.cfg.logger.log(`stream: ${sql}`)
97
98
 
98
- return (this.db.pool().query(sql).stream() as ReadableTyped<{ v: V }>).map(row => row.v)
99
+ return (this.db.pool().query(sql).stream() as ReadableTyped<{ v: Buffer }>).map(row => row.v)
99
100
  }
100
101
 
101
- streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>> {
102
+ streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
102
103
  let sql = `SELECT id,v FROM ${table}`
103
104
  if (limit) sql += ` LIMIT ${limit}`
104
105
  if (this.cfg.logSQL) this.db.cfg.logger.log(`stream: ${sql}`)
105
106
 
106
- return (this.db.pool().query(sql).stream() as ReadableTyped<KeyValueObject<V>>).map(row => [
107
+ return (this.db.pool().query(sql).stream() as ReadableTyped<KeyValueObject>).map(row => [
107
108
  row.id,
108
109
  row.v,
109
110
  ])
@@ -125,10 +126,6 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
125
126
  return rows[0]!.cnt
126
127
  }
127
128
 
128
- async increment(_table: string, _id: string, _by?: number): Promise<number> {
129
- throw new AppError('MySQLKeyValueDB.increment() is not implemented')
130
- }
131
-
132
129
  async incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]> {
133
130
  throw new AppError('MySQLKeyValueDB.incrementBatch() is not implemented')
134
131
  }