@naturalcycles/db-lib 10.43.0 → 10.44.0
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.
- package/dist/commondao/common.dao.d.ts +1 -1
- package/dist/commondao/common.dao.js +1 -1
- package/dist/kv/commonSyncKeyValueDB.d.ts +56 -0
- package/dist/kv/commonSyncKeyValueDB.js +1 -0
- package/dist/kv/index.d.ts +1 -0
- package/dist/kv/index.js +1 -0
- package/package.json +1 -1
- package/src/commondao/common.dao.ts +2 -2
- package/src/kv/commonSyncKeyValueDB.ts +74 -0
- package/src/kv/index.ts +1 -0
|
@@ -201,7 +201,7 @@ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
201
201
|
* return dbm
|
|
202
202
|
* }
|
|
203
203
|
*/
|
|
204
|
-
static decompressLegacyRow<T extends ObjectWithId>(row: T): Promise<T>;
|
|
204
|
+
static decompressLegacyRow<T extends ObjectWithId>(this: void, row: T): Promise<T>;
|
|
205
205
|
/**
|
|
206
206
|
* Temporary helper to migrate from the old `data` compressed property to the new `__compressed` property.
|
|
207
207
|
* Use as your `beforeDBMToBM` hook during the migration period.
|
|
@@ -89,7 +89,7 @@ export class CommonDao {
|
|
|
89
89
|
if (!id)
|
|
90
90
|
return null;
|
|
91
91
|
const [row] = await this.loadByIds([id], opt);
|
|
92
|
-
return await
|
|
92
|
+
return await this.anyToDBM(row, opt);
|
|
93
93
|
}
|
|
94
94
|
async getByIds(ids, opt = {}) {
|
|
95
95
|
const dbms = await this.loadByIds(ids, opt);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Pipeline } from '@naturalcycles/nodejs-lib/stream';
|
|
2
|
+
import type { CommonDBCreateOptions } from '../db.model.js';
|
|
3
|
+
import type { CommonKeyValueDBSaveBatchOptions, CommonKeyValueDBSupport, IncrementTuple, KeyValueDBTuple } from './commonKeyValueDB.js';
|
|
4
|
+
/**
|
|
5
|
+
* Common interface for Synchronous Key-Value database implementations.
|
|
6
|
+
* Same as CommonKeyValueDB, but with a sync implementation,
|
|
7
|
+
* modeled after e.g SQLite in Node.js, which is designed to be sync.
|
|
8
|
+
*
|
|
9
|
+
* Methods use `Sync` postfix to allow one implementation to support
|
|
10
|
+
* both async and sync CommonKeyValueDB interfaces.
|
|
11
|
+
*
|
|
12
|
+
* @experimental
|
|
13
|
+
*/
|
|
14
|
+
export interface CommonSyncKeyValueDB {
|
|
15
|
+
/**
|
|
16
|
+
* Manifest of supported features.
|
|
17
|
+
*/
|
|
18
|
+
support: CommonKeyValueDBSupport;
|
|
19
|
+
/**
|
|
20
|
+
* Check that DB connection is working properly.
|
|
21
|
+
*/
|
|
22
|
+
pingSync: () => void;
|
|
23
|
+
/**
|
|
24
|
+
* Will do like `create table ...` for mysql.
|
|
25
|
+
* Caution! dropIfExists defaults to false. If set to true - will actually DROP the table!
|
|
26
|
+
*/
|
|
27
|
+
createTableSync: (table: string, opt?: CommonDBCreateOptions) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Returns an array of tuples [key, value]. Not found values are not returned (no error is thrown).
|
|
30
|
+
*
|
|
31
|
+
* Currently it is NOT required to maintain the same order as input `ids`.
|
|
32
|
+
*/
|
|
33
|
+
getByIdsSync: (table: string, ids: string[]) => KeyValueDBTuple[];
|
|
34
|
+
deleteByIdsSync: (table: string, ids: string[]) => void;
|
|
35
|
+
saveBatchSync: (table: string, entries: KeyValueDBTuple[], opt?: CommonKeyValueDBSaveBatchOptions) => void;
|
|
36
|
+
streamIds: (table: string, limit?: number) => Pipeline<string>;
|
|
37
|
+
streamValues: (table: string, limit?: number) => Pipeline<Buffer>;
|
|
38
|
+
streamEntries: (table: string, limit?: number) => Pipeline<KeyValueDBTuple>;
|
|
39
|
+
countSync: (table: string) => number;
|
|
40
|
+
/**
|
|
41
|
+
* Perform a batch of Increment operations.
|
|
42
|
+
* Given entries array, increment each key of it (1st index of the tuple) by the given amount (2nd index of the tuple).
|
|
43
|
+
*
|
|
44
|
+
* Example:
|
|
45
|
+
* [
|
|
46
|
+
* ['key1', 2],
|
|
47
|
+
* ['key2', 3],
|
|
48
|
+
* ]
|
|
49
|
+
* would increment `key1` by 2, and `key2` by 3.
|
|
50
|
+
*
|
|
51
|
+
* Returns the entries array with tuples of the same structure, with updated numbers.
|
|
52
|
+
*
|
|
53
|
+
* @experimental
|
|
54
|
+
*/
|
|
55
|
+
incrementBatchSync: (table: string, entries: IncrementTuple[]) => IncrementTuple[];
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/kv/index.d.ts
CHANGED
package/dist/kv/index.js
CHANGED
package/package.json
CHANGED
|
@@ -137,7 +137,7 @@ export class CommonDao<
|
|
|
137
137
|
async getByIdAsDBM(id?: ID | null, opt: CommonDaoReadOptions = {}): Promise<DBM | null> {
|
|
138
138
|
if (!id) return null
|
|
139
139
|
const [row] = await this.loadByIds([id], opt)
|
|
140
|
-
return await
|
|
140
|
+
return await this.anyToDBM(row, opt)
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
async getByIds(ids: ID[], opt: CommonDaoReadOptions = {}): Promise<BM[]> {
|
|
@@ -989,7 +989,7 @@ export class CommonDao<
|
|
|
989
989
|
* return dbm
|
|
990
990
|
* }
|
|
991
991
|
*/
|
|
992
|
-
static async decompressLegacyRow<T extends ObjectWithId>(row: T): Promise<T> {
|
|
992
|
+
static async decompressLegacyRow<T extends ObjectWithId>(this: void, row: T): Promise<T> {
|
|
993
993
|
// Check both __compressed (current) and data (legacy) for backward compatibility
|
|
994
994
|
const compressed = (row as any).__compressed ?? (row as any).data
|
|
995
995
|
if (!Buffer.isBuffer(compressed)) return row
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Pipeline } from '@naturalcycles/nodejs-lib/stream'
|
|
2
|
+
import type { CommonDBCreateOptions } from '../db.model.js'
|
|
3
|
+
import type {
|
|
4
|
+
CommonKeyValueDBSaveBatchOptions,
|
|
5
|
+
CommonKeyValueDBSupport,
|
|
6
|
+
IncrementTuple,
|
|
7
|
+
KeyValueDBTuple,
|
|
8
|
+
} from './commonKeyValueDB.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Common interface for Synchronous Key-Value database implementations.
|
|
12
|
+
* Same as CommonKeyValueDB, but with a sync implementation,
|
|
13
|
+
* modeled after e.g SQLite in Node.js, which is designed to be sync.
|
|
14
|
+
*
|
|
15
|
+
* Methods use `Sync` postfix to allow one implementation to support
|
|
16
|
+
* both async and sync CommonKeyValueDB interfaces.
|
|
17
|
+
*
|
|
18
|
+
* @experimental
|
|
19
|
+
*/
|
|
20
|
+
export interface CommonSyncKeyValueDB {
|
|
21
|
+
/**
|
|
22
|
+
* Manifest of supported features.
|
|
23
|
+
*/
|
|
24
|
+
support: CommonKeyValueDBSupport
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check that DB connection is working properly.
|
|
28
|
+
*/
|
|
29
|
+
pingSync: () => void
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Will do like `create table ...` for mysql.
|
|
33
|
+
* Caution! dropIfExists defaults to false. If set to true - will actually DROP the table!
|
|
34
|
+
*/
|
|
35
|
+
createTableSync: (table: string, opt?: CommonDBCreateOptions) => void
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns an array of tuples [key, value]. Not found values are not returned (no error is thrown).
|
|
39
|
+
*
|
|
40
|
+
* Currently it is NOT required to maintain the same order as input `ids`.
|
|
41
|
+
*/
|
|
42
|
+
getByIdsSync: (table: string, ids: string[]) => KeyValueDBTuple[]
|
|
43
|
+
|
|
44
|
+
deleteByIdsSync: (table: string, ids: string[]) => void
|
|
45
|
+
|
|
46
|
+
saveBatchSync: (
|
|
47
|
+
table: string,
|
|
48
|
+
entries: KeyValueDBTuple[],
|
|
49
|
+
opt?: CommonKeyValueDBSaveBatchOptions,
|
|
50
|
+
) => void
|
|
51
|
+
|
|
52
|
+
streamIds: (table: string, limit?: number) => Pipeline<string>
|
|
53
|
+
streamValues: (table: string, limit?: number) => Pipeline<Buffer>
|
|
54
|
+
streamEntries: (table: string, limit?: number) => Pipeline<KeyValueDBTuple>
|
|
55
|
+
|
|
56
|
+
countSync: (table: string) => number
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Perform a batch of Increment operations.
|
|
60
|
+
* Given entries array, increment each key of it (1st index of the tuple) by the given amount (2nd index of the tuple).
|
|
61
|
+
*
|
|
62
|
+
* Example:
|
|
63
|
+
* [
|
|
64
|
+
* ['key1', 2],
|
|
65
|
+
* ['key2', 3],
|
|
66
|
+
* ]
|
|
67
|
+
* would increment `key1` by 2, and `key2` by 3.
|
|
68
|
+
*
|
|
69
|
+
* Returns the entries array with tuples of the same structure, with updated numbers.
|
|
70
|
+
*
|
|
71
|
+
* @experimental
|
|
72
|
+
*/
|
|
73
|
+
incrementBatchSync: (table: string, entries: IncrementTuple[]) => IncrementTuple[]
|
|
74
|
+
}
|
package/src/kv/index.ts
CHANGED