Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit 27033f1

Browse files
fix: adapt to db-lib
1 parent 62ba326 commit 27033f1

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

src/mysqlKeyValueDB.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import {
22
CommonDBCreateOptions,
33
CommonKeyValueDB,
44
commonKeyValueDBFullSupport,
5-
KeyValueDBTuple,
65
} from '@naturalcycles/db-lib'
7-
import { AppError, ObjectWithId, pMap, StringMap } from '@naturalcycles/js-lib'
6+
import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB'
7+
import { AppError, KeyValueTuple, ObjectWithId, pMap } from '@naturalcycles/js-lib'
88
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
99
import { QueryOptions } from 'mysql'
1010
import { MysqlDB, MysqlDBCfg } from './mysql.db'
1111

12-
interface KeyValueObject {
12+
interface KeyValueObject<V> {
1313
id: string
14-
v: Buffer
14+
v: V
1515
}
1616

1717
export class MySQLKeyValueDB implements CommonKeyValueDB {
@@ -45,12 +45,12 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
4545
await this.db.runSQL({ sql })
4646
}
4747

48-
async getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]> {
48+
async getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]> {
4949
if (!ids.length) return []
5050

5151
const sql = `SELECT id,v FROM ${table} where id in (${ids.map(id => `"${id}"`).join(',')})`
5252

53-
const rows = await this.db.runSQL<KeyValueObject[]>({ sql })
53+
const rows = await this.db.runSQL<KeyValueObject<V>[]>({ sql })
5454

5555
return rows.map(({ id, v }) => [id, v])
5656
}
@@ -68,7 +68,7 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
6868
await this.db.runSQL({ sql })
6969
}
7070

71-
async saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void> {
71+
async saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void> {
7272
const statements: QueryOptions[] = entries.map(([id, buf]) => {
7373
return {
7474
sql: `INSERT INTO ${table} (id, v) VALUES (?, ?)`,
@@ -90,20 +90,20 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
9090
return (this.db.pool().query(sql).stream() as ReadableTyped<ObjectWithId>).map(row => row.id)
9191
}
9292

93-
streamValues(table: string, limit?: number): ReadableTyped<Buffer> {
93+
streamValues<V>(table: string, limit?: number): ReadableTyped<V> {
9494
let sql = `SELECT v FROM ${table}`
9595
if (limit) sql += ` LIMIT ${limit}`
9696
if (this.cfg.logSQL) this.db.cfg.logger.log(`stream: ${sql}`)
9797

98-
return (this.db.pool().query(sql).stream() as ReadableTyped<{ v: Buffer }>).map(row => row.v)
98+
return (this.db.pool().query(sql).stream() as ReadableTyped<{ v: V }>).map(row => row.v)
9999
}
100100

101-
streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
101+
streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>> {
102102
let sql = `SELECT id,v FROM ${table}`
103103
if (limit) sql += ` LIMIT ${limit}`
104104
if (this.cfg.logSQL) this.db.cfg.logger.log(`stream: ${sql}`)
105105

106-
return (this.db.pool().query(sql).stream() as ReadableTyped<KeyValueObject>).map(row => [
106+
return (this.db.pool().query(sql).stream() as ReadableTyped<KeyValueObject<V>>).map(row => [
107107
row.id,
108108
row.v,
109109
])
@@ -129,10 +129,7 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
129129
throw new AppError('MySQLKeyValueDB.increment() is not implemented')
130130
}
131131

132-
async incrementBatch(
133-
_table: string,
134-
_incrementMap: StringMap<number>,
135-
): Promise<StringMap<number>> {
132+
async incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]> {
136133
throw new AppError('MySQLKeyValueDB.incrementBatch() is not implemented')
137134
}
138135
}

yarn.lock

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,10 @@
507507
dependencies:
508508
"@jridgewell/trace-mapping" "0.3.9"
509509

510-
"@es-joy/jsdoccomment@~0.48.0":
511-
version "0.48.0"
512-
resolved "https://registry.yarnpkg.com/@es-joy/jsdoccomment/-/jsdoccomment-0.48.0.tgz#5d9dc1a295cf5d1ed224dffafb4800d5c7206c27"
513-
integrity sha512-G6QUWIcC+KvSwXNsJyDTHvqUdNoAVJPPgkc3+Uk4WBKqZvoXhlvazOgm9aL0HwihJLQf0l+tOE2UFzXBqCqgDw==
510+
"@es-joy/jsdoccomment@~0.49.0":
511+
version "0.49.0"
512+
resolved "https://registry.yarnpkg.com/@es-joy/jsdoccomment/-/jsdoccomment-0.49.0.tgz#e5ec1eda837c802eca67d3b29e577197f14ba1db"
513+
integrity sha512-xjZTSFgECpb9Ohuk5yMX5RhUEbfeQcuOp8IF60e+wyzWEF0M5xeSgqsfLtvPEX8BIyOX9saZqzuGPmZ8oWc+5Q==
514514
dependencies:
515515
comment-parser "1.4.1"
516516
esquery "^1.6.0"
@@ -1002,17 +1002,17 @@
10021002
typescript "^5.0.2"
10031003

10041004
"@naturalcycles/db-lib@^9.1.0":
1005-
version "9.22.0"
1006-
resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-9.22.0.tgz#d01153b033e22155ade705aa049fe089978c5798"
1007-
integrity sha512-989fWQqlfMrtoaKxzqWN2Eh7Y7MrJcqoq5wl7Uldm84eUe3OUY87H0BYgGr/1kO309l2EuzhEkkEzcuO9QyKJw==
1005+
version "9.22.1"
1006+
resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-9.22.1.tgz#debfd7d5dda951070441cb27e15fdf1aecd825ff"
1007+
integrity sha512-Y5AEdc/0pQKiJM7XHmaVrAB6AW+NZu70QbhGWINS+r/TPLuvnLFfi9KViiNmfByIS7WRNu1D2XNiZr3FbLgceg==
10081008
dependencies:
10091009
"@naturalcycles/js-lib" "^14.116.0"
10101010
"@naturalcycles/nodejs-lib" "^13.1.1"
10111011

10121012
"@naturalcycles/dev-lib@^15.18.0":
1013-
version "15.22.0"
1014-
resolved "https://registry.yarnpkg.com/@naturalcycles/dev-lib/-/dev-lib-15.22.0.tgz#f1a31b5e0483e2d5beaadf8e5bce9345789b9fef"
1015-
integrity sha512-QZQEvP2yM27hDATOOHoaNDXXphUwt/dDMbVd7RATQMGoSmjV8QYANJSisWLPAVAee1eF+yQ+t/SUDNrtFoLSXg==
1013+
version "15.23.0"
1014+
resolved "https://registry.yarnpkg.com/@naturalcycles/dev-lib/-/dev-lib-15.23.0.tgz#44de477d9f842bc6397a84649809e053b6b9628f"
1015+
integrity sha512-m1qbFzgmqDGerZYnDqtqlg6j1wc+MM/f6jKXBNHs4h90bAJtxXVG2pQaGoAaDdrsXHyT3eq6aE9iCZh7DjyIvw==
10161016
dependencies:
10171017
"@biomejs/biome" "^1.8.3"
10181018
"@commitlint/cli" "^19.0.0"
@@ -2125,11 +2125,11 @@ eslint-plugin-jest@^28.0.0:
21252125
"@typescript-eslint/utils" "^6.0.0 || ^7.0.0 || ^8.0.0"
21262126

21272127
eslint-plugin-jsdoc@^50.0.0:
2128-
version "50.3.2"
2129-
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.3.2.tgz#f9b8b3d70abe7a84e22a3bbadf22a935c6194b4a"
2130-
integrity sha512-TjgZocG53N3a84PdCFGqVMWLWwDitOUuKjlJftwTu/iTiD7N/Q2Q3eEy/Q4GfJqpM4rTJCkzUYWQfol6RZNDcA==
2128+
version "50.4.1"
2129+
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.4.1.tgz#845ddf4c395891babe135023d97a45c750d94c4c"
2130+
integrity sha512-OXIq+JJQPCLAKL473/esioFOwbXyRE5MAQ4HbZjcp3e+K3zdxt2uDpGs3FR+WezUXNStzEtTfgx15T+JFrVwBA==
21312131
dependencies:
2132-
"@es-joy/jsdoccomment" "~0.48.0"
2132+
"@es-joy/jsdoccomment" "~0.49.0"
21332133
are-docs-informative "^0.0.2"
21342134
comment-parser "1.4.1"
21352135
debug "^4.3.6"
@@ -2491,9 +2491,9 @@ get-caller-file@^2.0.5:
24912491
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
24922492

24932493
get-east-asian-width@^1.0.0:
2494-
version "1.2.0"
2495-
resolved "https://registry.yarnpkg.com/get-east-asian-width/-/get-east-asian-width-1.2.0.tgz#5e6ebd9baee6fb8b7b6bd505221065f0cd91f64e"
2496-
integrity sha512-2nk+7SIVb14QrgXFHcm84tD4bKQz0RxPuMT8Ag5KPOq7J5fEmAg0UbXdTOSHqNuHSU28k55qnceesxXRZGzKWA==
2494+
version "1.3.0"
2495+
resolved "https://registry.yarnpkg.com/get-east-asian-width/-/get-east-asian-width-1.3.0.tgz#21b4071ee58ed04ee0db653371b55b4299875389"
2496+
integrity sha512-vpeMIQKxczTD/0s2CdEWHcb0eeJe6TFjxb+J5xgX7hScxqrGuyjmv4c1D4A/gelKfyox0gJJwIHF+fLjeaM8kQ==
24972497

24982498
get-package-type@^0.1.0:
24992499
version "0.1.0"

0 commit comments

Comments
 (0)