ueberdb2 4.1.1 → 4.1.3
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/package.json +5 -3
- package/.eslintignore +0 -2
- package/.eslintrc.cjs +0 -66
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/npmpublish.yml +0 -134
- package/.travis.yml +0 -46
- package/CHANGELOG.md +0 -304
- package/CONTRIBUTING.md +0 -103
- package/SECURITY.md +0 -5
- package/databases/cassandra_db.ts +0 -265
- package/databases/couch_db.ts +0 -189
- package/databases/dirty_db.ts +0 -85
- package/databases/dirty_git_db.ts +0 -82
- package/databases/elasticsearch_db.ts +0 -257
- package/databases/memory_db.ts +0 -41
- package/databases/mock_db.ts +0 -43
- package/databases/mongodb_db.ts +0 -142
- package/databases/mssql_db.ts +0 -226
- package/databases/mysql_db.ts +0 -183
- package/databases/postgres_db.ts +0 -213
- package/databases/postgrespool_db.ts +0 -11
- package/databases/redis_db.ts +0 -129
- package/databases/rethink_db.ts +0 -114
- package/databases/sqlite_db.ts +0 -159
- package/docker-compose.yml +0 -44
- package/index.ts +0 -224
- package/lib/AbstractDatabase.ts +0 -79
- package/lib/CacheAndBufferLayer.ts +0 -665
- package/lib/logging.ts +0 -33
- package/test/lib/databases.ts +0 -73
- package/test/lib/mysql.sql +0 -84
- package/test/test.ts +0 -328
- package/test/test_bulk.ts +0 -69
- package/test/test_elasticsearch.ts +0 -128
- package/test/test_findKeys.ts +0 -41
- package/test/test_flush.ts +0 -55
- package/test/test_getSub.ts +0 -28
- package/test/test_lru.ts +0 -151
- package/test/test_memory.ts +0 -32
- package/test/test_metrics.ts +0 -734
- package/test/test_mysql.ts +0 -62
- package/test/test_postgres.ts +0 -16
- package/test/test_setSub.ts +0 -19
- package/test/test_tojson.ts +0 -34
package/databases/mysql_db.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 2011 Peter 'Pita' Martischka
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import AbstractDatabase, {Settings} from '../lib/AbstractDatabase';
|
|
18
|
-
import mysql from 'mysql';
|
|
19
|
-
import util from 'util';
|
|
20
|
-
import {BulkObject} from './cassandra_db';
|
|
21
|
-
|
|
22
|
-
export const Database = class extends AbstractDatabase {
|
|
23
|
-
private _mysqlSettings: Settings;
|
|
24
|
-
private _pool: any;
|
|
25
|
-
constructor(settings:Settings) {
|
|
26
|
-
super();
|
|
27
|
-
this.logger = console;
|
|
28
|
-
this._mysqlSettings = {
|
|
29
|
-
charset: 'utf8mb4', // temp hack needs a proper fix..
|
|
30
|
-
...settings,
|
|
31
|
-
};
|
|
32
|
-
this.settings = {
|
|
33
|
-
engine: 'InnoDB',
|
|
34
|
-
// Limit the query size to avoid timeouts or other failures.
|
|
35
|
-
bulkLimit: 100,
|
|
36
|
-
json: true,
|
|
37
|
-
queryTimeout: 60000,
|
|
38
|
-
};
|
|
39
|
-
this._pool = null; // Initialized in init();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get isAsync() { return true; }
|
|
43
|
-
|
|
44
|
-
async _query(options: any):Promise<any> {
|
|
45
|
-
try {
|
|
46
|
-
return await new Promise((resolve, reject) => {
|
|
47
|
-
options = {timeout: this.settings.queryTimeout, ...options};
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
this._pool && this._pool.query(options, (err, ...args) => err != null ? reject(err) : resolve(args));
|
|
50
|
-
});
|
|
51
|
-
} catch (err:any) {
|
|
52
|
-
this.logger.error(`${err.fatal ? 'Fatal ' : ''}MySQL error: ${err.stack || err}`);
|
|
53
|
-
throw err;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async init() {
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
this._pool = mysql.createPool(this._mysqlSettings);
|
|
60
|
-
const {database, charset} = this._mysqlSettings;
|
|
61
|
-
|
|
62
|
-
const sqlCreate = `${'CREATE TABLE IF NOT EXISTS `store` ( ' +
|
|
63
|
-
'`key` VARCHAR( 100 ) NOT NULL COLLATE utf8mb4_bin, ' +
|
|
64
|
-
'`value` LONGTEXT COLLATE utf8mb4_bin NOT NULL , ' +
|
|
65
|
-
'PRIMARY KEY ( `key` ) ' +
|
|
66
|
-
') ENGINE='}${this.settings.engine} CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`;
|
|
67
|
-
|
|
68
|
-
const sqlAlter = 'ALTER TABLE store MODIFY `key` VARCHAR(100) COLLATE utf8mb4_bin;';
|
|
69
|
-
|
|
70
|
-
await this._query({sql: sqlCreate});
|
|
71
|
-
|
|
72
|
-
// Checks for Database charset et al
|
|
73
|
-
const dbCharSet =
|
|
74
|
-
'SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME ' +
|
|
75
|
-
`FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${database}'`;
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
let [result] = await this._query({sql: dbCharSet});
|
|
78
|
-
|
|
79
|
-
result = JSON.parse(JSON.stringify(result));
|
|
80
|
-
if (result[0].DEFAULT_CHARACTER_SET_NAME !== charset) {
|
|
81
|
-
this.logger.error(`Database is not configured with charset ${charset} -- ` +
|
|
82
|
-
'This may lead to crashes when certain characters are pasted in pads');
|
|
83
|
-
this.logger.log(result[0], charset);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (result[0].DEFAULT_COLLATION_NAME.indexOf(charset) === -1) {
|
|
87
|
-
this.logger.error(
|
|
88
|
-
`Database is not configured with collation name that includes ${charset} -- ` +
|
|
89
|
-
'This may lead to crashes when certain characters are pasted in pads');
|
|
90
|
-
this.logger.log(result[0], charset, result[0].DEFAULT_COLLATION_NAME);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const tableCharSet =
|
|
94
|
-
'SELECT CCSA.character_set_name AS character_set_name ' +
|
|
95
|
-
'FROM information_schema.`TABLES` ' +
|
|
96
|
-
'T,information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA ' +
|
|
97
|
-
'WHERE CCSA.collation_name = T.table_collation ' +
|
|
98
|
-
`AND T.table_schema = '${database}' ` +
|
|
99
|
-
"AND T.table_name = 'store'";
|
|
100
|
-
[result] = await this._query({sql: tableCharSet});
|
|
101
|
-
if (!result[0]) {
|
|
102
|
-
this.logger.warn('Data has no character_set_name value -- ' +
|
|
103
|
-
'This may lead to crashes when certain characters are pasted in pads');
|
|
104
|
-
}
|
|
105
|
-
if (result[0] && (result[0].character_set_name !== charset)) {
|
|
106
|
-
this.logger.error(`table is not configured with charset ${charset} -- ` +
|
|
107
|
-
'This may lead to crashes when certain characters are pasted in pads');
|
|
108
|
-
this.logger.log(result[0], charset);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// check migration level, alter if not migrated
|
|
112
|
-
const level = await this.get('MYSQL_MIGRATION_LEVEL');
|
|
113
|
-
|
|
114
|
-
if (level !== '1') {
|
|
115
|
-
await this._query({sql: sqlAlter});
|
|
116
|
-
await this.set('MYSQL_MIGRATION_LEVEL', '1');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async get(key:string) {
|
|
121
|
-
const [results] = await this._query({
|
|
122
|
-
sql: 'SELECT `value` FROM `store` WHERE `key` = ? AND BINARY `key` = ?',
|
|
123
|
-
values: [key, key],
|
|
124
|
-
});
|
|
125
|
-
return results.length === 1 ? results[0].value : null;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async findKeys(key:string, notKey:string) {
|
|
129
|
-
let query = 'SELECT `key` FROM `store` WHERE `key` LIKE ?';
|
|
130
|
-
const params = [];
|
|
131
|
-
|
|
132
|
-
// desired keys are key, e.g. pad:%
|
|
133
|
-
key = key.replace(/\*/g, '%');
|
|
134
|
-
params.push(key);
|
|
135
|
-
|
|
136
|
-
if (notKey != null) {
|
|
137
|
-
// not desired keys are notKey, e.g. %:%:%
|
|
138
|
-
notKey = notKey.replace(/\*/g, '%');
|
|
139
|
-
query += ' AND `key` NOT LIKE ?';
|
|
140
|
-
params.push(notKey);
|
|
141
|
-
}
|
|
142
|
-
const [results] = await this._query({sql: query, values: params});
|
|
143
|
-
return results.map((val:{key:string}) => val.key);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async set(key:string, value:string) {
|
|
147
|
-
if (key.length > 100) throw new Error('Your Key can only be 100 chars');
|
|
148
|
-
await this._query({sql: 'REPLACE INTO `store` VALUES (?,?)', values: [key, value]});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async remove(key:string) {
|
|
152
|
-
await this._query({
|
|
153
|
-
sql: 'DELETE FROM `store` WHERE `key` = ? AND BINARY `key` = ?',
|
|
154
|
-
values: [key, key],
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async doBulk(bulk:BulkObject[]) {
|
|
159
|
-
const replaces = [];
|
|
160
|
-
const deletes = [];
|
|
161
|
-
for (const op of bulk) {
|
|
162
|
-
switch (op.type) {
|
|
163
|
-
case 'set': replaces.push([op.key, op.value]); break;
|
|
164
|
-
case 'remove': deletes.push(op.key); break;
|
|
165
|
-
default: throw new Error(`unknown op type: ${op.type}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
await Promise.all([
|
|
169
|
-
replaces.length ? this._query({
|
|
170
|
-
sql: 'REPLACE INTO `store` VALUES ?;',
|
|
171
|
-
values: [replaces],
|
|
172
|
-
}) : null,
|
|
173
|
-
deletes.length ? this._query({
|
|
174
|
-
sql: 'DELETE FROM `store` WHERE `key` IN (?) AND BINARY `key` IN (?);',
|
|
175
|
-
values: [deletes, deletes],
|
|
176
|
-
}) : null,
|
|
177
|
-
]);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async close() {
|
|
181
|
-
await util.promisify(this._pool.end.bind(this._pool))();
|
|
182
|
-
}
|
|
183
|
-
};
|
package/databases/postgres_db.ts
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 2011 Peter 'Pita' Martischka
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import AbstractDatabase, {Settings} from '../lib/AbstractDatabase';
|
|
18
|
-
import async from 'async';
|
|
19
|
-
import pg, {Pool, QueryResult} from 'pg';
|
|
20
|
-
import {BulkObject} from './cassandra_db';
|
|
21
|
-
|
|
22
|
-
export const Database = class extends AbstractDatabase {
|
|
23
|
-
private db: Pool;
|
|
24
|
-
private upsertStatement: string | null | undefined;
|
|
25
|
-
constructor(settings:Settings | string) {
|
|
26
|
-
super();
|
|
27
|
-
if (typeof settings === 'string') settings = {connectionString: settings};
|
|
28
|
-
this.settings = settings;
|
|
29
|
-
|
|
30
|
-
this.settings.cache = settings.cache || 1000;
|
|
31
|
-
this.settings.writeInterval = 100;
|
|
32
|
-
this.settings.json = true;
|
|
33
|
-
|
|
34
|
-
// Pool specific defaults
|
|
35
|
-
this.settings.max = this.settings.max || 20;
|
|
36
|
-
this.settings.min = this.settings.min || 4;
|
|
37
|
-
this.settings.idleTimeoutMillis = this.settings.idleTimeoutMillis || 1000;
|
|
38
|
-
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
this.db = new pg.Pool(this.settings);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
init(callback: (err: Error)=>{}) {
|
|
44
|
-
const testTableExists = "SELECT 1 as exists FROM pg_tables WHERE tablename = 'store'";
|
|
45
|
-
|
|
46
|
-
const createTable = 'CREATE TABLE IF NOT EXISTS store (' +
|
|
47
|
-
'"key" character varying(100) NOT NULL, ' +
|
|
48
|
-
'"value" text NOT NULL, ' +
|
|
49
|
-
'CONSTRAINT store_pkey PRIMARY KEY (key))';
|
|
50
|
-
|
|
51
|
-
// this variable will be given a value depending on the result of the
|
|
52
|
-
// feature detection
|
|
53
|
-
this.upsertStatement = null;
|
|
54
|
-
|
|
55
|
-
/*
|
|
56
|
-
* - Detects if this Postgres version supports INSERT .. ON CONFLICT
|
|
57
|
-
* UPDATE (PostgreSQL >= 9.5 and CockroachDB)
|
|
58
|
-
* - If upsert is not supported natively, creates in the DB a pl/pgsql
|
|
59
|
-
* function that emulates it
|
|
60
|
-
* - Performs a side effect, setting this.upsertStatement to the sql
|
|
61
|
-
* statement that needs to be used, based on the detection result
|
|
62
|
-
* - calls the callback
|
|
63
|
-
*/
|
|
64
|
-
const detectUpsertMethod = (callback: (err?: Error) => {}) => {
|
|
65
|
-
const upsertViaFunction = 'SELECT ueberdb_insert_or_update($1,$2)';
|
|
66
|
-
const upsertNatively =
|
|
67
|
-
'INSERT INTO store(key, value) VALUES ($1, $2) ' +
|
|
68
|
-
'ON CONFLICT (key) DO UPDATE SET value = excluded.value';
|
|
69
|
-
const createFunc =
|
|
70
|
-
'CREATE OR REPLACE FUNCTION ueberdb_insert_or_update(character varying, text) ' +
|
|
71
|
-
'RETURNS void AS $$ ' +
|
|
72
|
-
'BEGIN ' +
|
|
73
|
-
' IF EXISTS( SELECT * FROM store WHERE key = $1 ) THEN ' +
|
|
74
|
-
' UPDATE store SET value = $2 WHERE key = $1; ' +
|
|
75
|
-
' ELSE ' +
|
|
76
|
-
' INSERT INTO store(key,value) VALUES( $1, $2 ); ' +
|
|
77
|
-
' END IF; ' +
|
|
78
|
-
' RETURN; ' +
|
|
79
|
-
'END; ' +
|
|
80
|
-
'$$ LANGUAGE plpgsql;';
|
|
81
|
-
|
|
82
|
-
const testNativeUpsert = `EXPLAIN ${upsertNatively}`;
|
|
83
|
-
|
|
84
|
-
this.db.query(testNativeUpsert, ['test-key', 'test-value'], (err) => {
|
|
85
|
-
if (err) {
|
|
86
|
-
// the UPSERT statement failed: we will have to emulate it via
|
|
87
|
-
// an sql function
|
|
88
|
-
this.upsertStatement = upsertViaFunction;
|
|
89
|
-
|
|
90
|
-
// actually create the emulation function
|
|
91
|
-
this.db.query(createFunc, [], callback);
|
|
92
|
-
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// if we get here, the EXPLAIN UPSERT succeeded, and we can use a
|
|
97
|
-
// native UPSERT
|
|
98
|
-
this.upsertStatement = upsertNatively;
|
|
99
|
-
callback();
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
this.db.query(testTableExists, (err, result) => {
|
|
104
|
-
if (err != null) return callback(err);
|
|
105
|
-
if (result.rows.length === 0) {
|
|
106
|
-
this.db.query(createTable, (err) => {
|
|
107
|
-
if (err != null) return callback(err);
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
detectUpsertMethod(callback);
|
|
110
|
-
});
|
|
111
|
-
} else {
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
detectUpsertMethod(callback);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
get(key:string, callback: (err: Error | null, value: any)=>{}) {
|
|
119
|
-
this.db.query('SELECT value FROM store WHERE key=$1', [key], (err, results) => {
|
|
120
|
-
let value = null;
|
|
121
|
-
|
|
122
|
-
if (!err && results.rows.length === 1) {
|
|
123
|
-
value = results.rows[0].value;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
callback(err, value);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
findKeys(key:string, notKey:string, callback: (err: Error | null, value: any)=>{}) {
|
|
131
|
-
let query = 'SELECT key FROM store WHERE key LIKE $1';
|
|
132
|
-
const params = [];
|
|
133
|
-
// desired keys are %key:%, e.g. pad:%
|
|
134
|
-
key = key.replace(/\*/g, '%');
|
|
135
|
-
params.push(key);
|
|
136
|
-
|
|
137
|
-
if (notKey != null) {
|
|
138
|
-
// not desired keys are notKey:%, e.g. %:%:%
|
|
139
|
-
notKey = notKey.replace(/\*/g, '%');
|
|
140
|
-
query += ' AND key NOT LIKE $2';
|
|
141
|
-
params.push(notKey);
|
|
142
|
-
}
|
|
143
|
-
this.db.query(query, params, (err, results) => {
|
|
144
|
-
const value:string[] = [];
|
|
145
|
-
|
|
146
|
-
if (!err && results.rows.length > 0) {
|
|
147
|
-
results.rows.forEach((val) => {
|
|
148
|
-
value.push(val.key);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
callback(err, value);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
set(key:string, value:string, callback:(err: Error, result: QueryResult<any>) => void) {
|
|
157
|
-
if (key.length > 100) {
|
|
158
|
-
const val = '' as any;
|
|
159
|
-
callback(Error('Your Key can only be 100 chars'), val);
|
|
160
|
-
} else if (this.upsertStatement != null) {
|
|
161
|
-
this.db.query(this.upsertStatement, [key, value], callback);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
remove(key:string, callback:()=>{}) {
|
|
166
|
-
this.db.query('DELETE FROM store WHERE key=$1', [key], callback);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
doBulk(bulk:BulkObject[], callback:()=>{}) {
|
|
170
|
-
const replaceVALs = [];
|
|
171
|
-
let removeSQL = 'DELETE FROM store WHERE key IN (';
|
|
172
|
-
const removeVALs: string[] = [];
|
|
173
|
-
|
|
174
|
-
let removeCount = 0;
|
|
175
|
-
|
|
176
|
-
for (const i in bulk) {
|
|
177
|
-
if (bulk[i].type === 'set') {
|
|
178
|
-
replaceVALs.push([bulk[i].key, bulk[i].value]);
|
|
179
|
-
} else if (bulk[i].type === 'remove') {
|
|
180
|
-
if (removeCount !== 0) removeSQL += ',';
|
|
181
|
-
removeCount += 1;
|
|
182
|
-
|
|
183
|
-
removeSQL += `$${removeCount}`;
|
|
184
|
-
removeVALs.push(bulk[i].key);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
removeSQL += ');';
|
|
189
|
-
|
|
190
|
-
if (!this.upsertStatement) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// @ts-ignore
|
|
196
|
-
const functions = replaceVALs.map((v) => (cb:()=>{}) => this.db.query(this.upsertStatement, v, cb));
|
|
197
|
-
|
|
198
|
-
const removeFunction = (callback: ()=>{}) => {
|
|
199
|
-
// @ts-ignore
|
|
200
|
-
if (!(removeVALs.length) > 1) {
|
|
201
|
-
this.db.query(removeSQL, removeVALs, callback);
|
|
202
|
-
} else { callback(); }
|
|
203
|
-
};
|
|
204
|
-
functions.push(removeFunction);
|
|
205
|
-
|
|
206
|
-
// @ts-ignore
|
|
207
|
-
async.parallel(functions, callback);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
close(callback:()=>{}) {
|
|
211
|
-
this.db.end(callback);
|
|
212
|
-
}
|
|
213
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {Settings} from '../lib/AbstractDatabase';
|
|
2
|
-
|
|
3
|
-
const postgres = require('./postgres_db');
|
|
4
|
-
|
|
5
|
-
export const Database = class PostgresDB extends postgres.Database {
|
|
6
|
-
constructor(settings:Settings) {
|
|
7
|
-
console.warn('ueberdb: The postgrespool database driver is deprecated ' +
|
|
8
|
-
'and will be removed in a future version. Use postgres instead.');
|
|
9
|
-
super(settings);
|
|
10
|
-
}
|
|
11
|
-
};
|
package/databases/redis_db.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 2011 Peter 'Pita' Martischka
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import AbstractDatabase, {Settings} from '../lib/AbstractDatabase';
|
|
18
|
-
import {createClient, RedisScripts, RedisFunctions, RedisModules} from 'redis';
|
|
19
|
-
import {BulkObject} from './cassandra_db';
|
|
20
|
-
import {RedisClientType} from '@redis/client';
|
|
21
|
-
|
|
22
|
-
export const Database = class RedisDB extends AbstractDatabase {
|
|
23
|
-
private _client: RedisClientType<{graph:
|
|
24
|
-
{CONFIG_GET: typeof import('@redis/graph/dist/commands/CONFIG_GET');
|
|
25
|
-
configGet: typeof import('@redis/graph/dist/commands/CONFIG_GET');
|
|
26
|
-
CONFIG_SET: typeof import('@redis/graph/dist/commands/CONFIG_SET');
|
|
27
|
-
configSet: typeof import('@redis/graph/dist/commands/CONFIG_SET');
|
|
28
|
-
DELETE: typeof import('@redis/graph/dist/commands/DELETE');
|
|
29
|
-
delete: typeof import('@redis/graph/dist/commands/DELETE');
|
|
30
|
-
EXPLAIN: typeof import('@redis/graph/dist/commands/EXPLAIN');
|
|
31
|
-
explain: typeof import('@redis/graph/dist/commands/EXPLAIN');
|
|
32
|
-
LIST: typeof import('@redis/graph/dist/commands/LIST');
|
|
33
|
-
list: typeof import('@redis/graph/dist/commands/LIST');
|
|
34
|
-
PROFILE: typeof import('@redis/graph/dist/commands/PROFILE');
|
|
35
|
-
profile: typeof import('@redis/graph/dist/commands/PROFILE');
|
|
36
|
-
QUERY: typeof import('@redis/graph/dist/commands/QUERY');
|
|
37
|
-
query: typeof import('@redis/graph/dist/commands/QUERY');
|
|
38
|
-
RO_QUERY: typeof import('@redis/graph/dist/commands/RO_QUERY');
|
|
39
|
-
roQuery: typeof import('@redis/graph/dist/commands/RO_QUERY');
|
|
40
|
-
SLOWLOG: typeof import('@redis/graph/dist/commands/SLOWLOG');
|
|
41
|
-
slowLog: typeof import('@redis/graph/dist/commands/SLOWLOG');};
|
|
42
|
-
json: {ARRAPPEND: typeof import('@redis/json/dist/commands/ARRAPPEND');
|
|
43
|
-
arrAppend: typeof import('@redis/json/dist/commands/ARRAPPEND');
|
|
44
|
-
ARRINDEX: typeof import('@redis/json/dist/commands/ARRINDEX');
|
|
45
|
-
arrIndex: typeof import('@redis/json/dist/commands/ARRINDEX');
|
|
46
|
-
ARRINSERT: typeof import('@redis/json/dist/commands/ARRINSERT');
|
|
47
|
-
arrInsert: typeof import('@redis/json/dist/commands/ARRINSERT'); ARRLEN: typeof import('@redis/json/dist/commands/ARRLEN'); arrLen: typeof import('@redis/json/dist/commands/ARRLEN'); ARRPOP: typeof import('@redis/json/dist/commands/ARRPOP'); arrPop: typeof import('@redis/json/dist/commands/ARRPOP'); ARRTRIM: typeof import('@redis/json/dist/commands/ARRTRIM'); arrTrim: typeof import('@redis/json/dist/commands/ARRTRIM'); DEBUG_MEMORY: typeof import('@redis/json/dist/commands/DEBUG_MEMORY'); debugMemory: typeof import('@redis/json/dist/commands/DEBUG_MEMORY'); DEL: typeof import('@redis/json/dist/commands/DEL'); del: typeof import('@redis/json/dist/commands/DEL'); FORGET: typeof import('@redis/json/dist/commands/FORGET'); forget: typeof import('@redis/json/dist/commands/FORGET'); GET: typeof import('@redis/json/dist/commands/GET'); get: typeof import('@redis/json/dist/commands/GET'); MGET: typeof import('@redis/json/dist/commands/MGET'); mGet: typeof import('@redis/json/dist/commands/MGET'); NUMINCRBY: typeof import('@redis/json/dist/commands/NUMINCRBY'); numIncrBy: typeof import('@redis/json/dist/commands/NUMINCRBY'); NUMMULTBY: typeof import('@redis/json/dist/commands/NUMMULTBY'); numMultBy: typeof import('@redis/json/dist/commands/NUMMULTBY'); OBJKEYS: typeof import('@redis/json/dist/commands/OBJKEYS'); objKeys: typeof import('@redis/json/dist/commands/OBJKEYS'); OBJLEN: typeof import('@redis/json/dist/commands/OBJLEN'); objLen: typeof import('@redis/json/dist/commands/OBJLEN'); RESP: typeof import('@redis/json/dist/commands/RESP'); resp: typeof import('@redis/json/dist/commands/RESP'); SET: typeof import('@redis/json/dist/commands/SET'); set: typeof import('@redis/json/dist/commands/SET'); STRAPPEND: typeof import('@redis/json/dist/commands/STRAPPEND'); strAppend: typeof import('@redis/json/dist/commands/STRAPPEND'); STRLEN: typeof import('@redis/json/dist/commands/STRLEN'); strLen: typeof import('@redis/json/dist/commands/STRLEN'); TYPE: typeof import('@redis/json/dist/commands/TYPE'); type: typeof import('@redis/json/dist/commands/TYPE');}; ft: {_LIST: typeof import('@redis/search/dist/commands/_LIST'); _list: typeof import('@redis/search/dist/commands/_LIST'); ALTER: typeof import('@redis/search/dist/commands/ALTER'); alter: typeof import('@redis/search/dist/commands/ALTER'); AGGREGATE_WITHCURSOR: typeof import('@redis/search/dist/commands/AGGREGATE_WITHCURSOR'); aggregateWithCursor: typeof import('@redis/search/dist/commands/AGGREGATE_WITHCURSOR'); AGGREGATE: typeof import('@redis/search/dist/commands/AGGREGATE'); aggregate: typeof import('@redis/search/dist/commands/AGGREGATE'); ALIASADD: typeof import('@redis/search/dist/commands/ALIASADD'); aliasAdd: typeof import('@redis/search/dist/commands/ALIASADD'); ALIASDEL: typeof import('@redis/search/dist/commands/ALIASDEL'); aliasDel: typeof import('@redis/search/dist/commands/ALIASDEL'); ALIASUPDATE: typeof import('@redis/search/dist/commands/ALIASUPDATE'); aliasUpdate: typeof import('@redis/search/dist/commands/ALIASUPDATE'); CONFIG_GET: typeof import('@redis/search/dist/commands/CONFIG_GET'); configGet: typeof import('@redis/search/dist/commands/CONFIG_GET'); CONFIG_SET: typeof import('@redis/search/dist/commands/CONFIG_SET'); configSet: typeof import('@redis/search/dist/commands/CONFIG_SET'); CREATE: typeof import('@redis/search/dist/commands/CREATE'); create: typeof import('@redis/search/dist/commands/CREATE'); CURSOR_DEL: typeof import('@redis/search/dist/commands/CURSOR_DEL'); cursorDel: typeof import('@redis/search/dist/commands/CURSOR_DEL'); CURSOR_READ: typeof import('@redis/search/dist/commands/CURSOR_READ'); cursorRead: typeof import('@redis/search/dist/commands/CURSOR_READ'); DICTADD: typeof import('@redis/search/dist/commands/DICTADD'); dictAdd: typeof import('@redis/search/dist/commands/DICTADD'); DICTDEL: typeof import('@redis/search/dist/commands/DICTDEL'); dictDel: typeof import('@redis/search/dist/commands/DICTDEL'); DICTDUMP: typeof import('@redis/search/dist/commands/DICTDUMP'); dictDump: typeof import('@redis/search/dist/commands/DICTDUMP'); DROPINDEX: typeof import('@redis/search/dist/commands/DROPINDEX'); dropIndex: typeof import('@redis/search/dist/commands/DROPINDEX'); EXPLAIN: typeof import('@redis/search/dist/commands/EXPLAIN'); explain: typeof import('@redis/search/dist/commands/EXPLAIN'); EXPLAINCLI: typeof import('@redis/search/dist/commands/EXPLAINCLI'); explainCli: typeof import('@redis/search/dist/commands/EXPLAINCLI'); INFO: typeof import('@redis/search/dist/commands/INFO'); info: typeof import('@redis/search/dist/commands/INFO'); PROFILESEARCH: typeof import('@redis/search/dist/commands/PROFILE_SEARCH'); profileSearch: typeof import('@redis/search/dist/commands/PROFILE_SEARCH'); PROFILEAGGREGATE: typeof import('@redis/search/dist/commands/PROFILE_AGGREGATE'); profileAggregate: typeof import('@redis/search/dist/commands/PROFILE_AGGREGATE'); SEARCH: typeof import('@redis/search/dist/commands/SEARCH'); search: typeof import('@redis/search/dist/commands/SEARCH'); SPELLCHECK: typeof import('@redis/search/dist/commands/SPELLCHECK'); spellCheck: typeof import('@redis/search/dist/commands/SPELLCHECK'); SUGADD: typeof import('@redis/search/dist/commands/SUGADD'); sugAdd: typeof import('@redis/search/dist/commands/SUGADD'); SUGDEL: typeof import('@redis/search/dist/commands/SUGDEL'); sugDel: typeof import('@redis/search/dist/commands/SUGDEL'); SUGGET_WITHPAYLOADS: typeof import('@redis/search/dist/commands/SUGGET_WITHPAYLOADS'); sugGetWithPayloads: typeof import('@redis/search/dist/commands/SUGGET_WITHPAYLOADS'); SUGGET_WITHSCORES_WITHPAYLOADS: typeof import('@redis/search/dist/commands/SUGGET_WITHSCORES_WITHPAYLOADS'); sugGetWithScoresWithPayloads: typeof import('@redis/search/dist/commands/SUGGET_WITHSCORES_WITHPAYLOADS'); SUGGET_WITHSCORES: typeof import('@redis/search/dist/commands/SUGGET_WITHSCORES'); sugGetWithScores: typeof import('@redis/search/dist/commands/SUGGET_WITHSCORES'); SUGGET: typeof import('@redis/search/dist/commands/SUGGET'); sugGet: typeof import('@redis/search/dist/commands/SUGGET'); SUGLEN: typeof import('@redis/search/dist/commands/SUGLEN'); sugLen: typeof import('@redis/search/dist/commands/SUGLEN'); SYNDUMP: typeof import('@redis/search/dist/commands/SYNDUMP'); synDump: typeof import('@redis/search/dist/commands/SYNDUMP'); SYNUPDATE: typeof import('@redis/search/dist/commands/SYNUPDATE'); synUpdate: typeof import('@redis/search/dist/commands/SYNUPDATE'); TAGVALS: typeof import('@redis/search/dist/commands/TAGVALS'); tagVals: typeof import('@redis/search/dist/commands/TAGVALS');}; ts: {ADD: typeof import('@redis/time-series/dist/commands/ADD'); add: typeof import('@redis/time-series/dist/commands/ADD'); ALTER: typeof import('@redis/time-series/dist/commands/ALTER'); alter: typeof import('@redis/time-series/dist/commands/ALTER'); CREATE: typeof import('@redis/time-series/dist/commands/CREATE'); create: typeof import('@redis/time-series/dist/commands/CREATE'); CREATERULE: typeof import('@redis/time-series/dist/commands/CREATERULE'); createRule: typeof import('@redis/time-series/dist/commands/CREATERULE'); DECRBY: typeof import('@redis/time-series/dist/commands/DECRBY'); decrBy: typeof import('@redis/time-series/dist/commands/DECRBY'); DEL: typeof import('@redis/time-series/dist/commands/DEL'); del: typeof import('@redis/time-series/dist/commands/DEL'); DELETERULE: typeof import('@redis/time-series/dist/commands/DELETERULE'); deleteRule: typeof import('@redis/time-series/dist/commands/DELETERULE'); GET: typeof import('@redis/time-series/dist/commands/GET'); get: typeof import('@redis/time-series/dist/commands/GET'); INCRBY: typeof import('@redis/time-series/dist/commands/INCRBY'); incrBy: typeof import('@redis/time-series/dist/commands/INCRBY'); INFO_DEBUG: typeof import('@redis/time-series/dist/commands/INFO_DEBUG'); infoDebug: typeof import('@redis/time-series/dist/commands/INFO_DEBUG'); INFO: typeof import('@redis/time-series/dist/commands/INFO'); info: typeof import('@redis/time-series/dist/commands/INFO'); MADD: typeof import('@redis/time-series/dist/commands/MADD'); mAdd: typeof import('@redis/time-series/dist/commands/MADD'); MGET: typeof import('@redis/time-series/dist/commands/MGET'); mGet: typeof import('@redis/time-series/dist/commands/MGET'); MGET_WITHLABELS: typeof import('@redis/time-series/dist/commands/MGET_WITHLABELS'); mGetWithLabels: typeof import('@redis/time-series/dist/commands/MGET_WITHLABELS'); QUERYINDEX: typeof import('@redis/time-series/dist/commands/QUERYINDEX'); queryIndex: typeof import('@redis/time-series/dist/commands/QUERYINDEX'); RANGE: typeof import('@redis/time-series/dist/commands/RANGE'); range: typeof import('@redis/time-series/dist/commands/RANGE'); REVRANGE: typeof import('@redis/time-series/dist/commands/REVRANGE'); revRange: typeof import('@redis/time-series/dist/commands/REVRANGE'); MRANGE: typeof import('@redis/time-series/dist/commands/MRANGE'); mRange: typeof import('@redis/time-series/dist/commands/MRANGE'); MRANGE_WITHLABELS: typeof import('@redis/time-series/dist/commands/MRANGE_WITHLABELS'); mRangeWithLabels: typeof import('@redis/time-series/dist/commands/MRANGE_WITHLABELS'); MREVRANGE: typeof import('@redis/time-series/dist/commands/MREVRANGE'); mRevRange: typeof import('@redis/time-series/dist/commands/MREVRANGE'); MREVRANGE_WITHLABELS: typeof import('@redis/time-series/dist/commands/MREVRANGE_WITHLABELS'); mRevRangeWithLabels: typeof import('@redis/time-series/dist/commands/MREVRANGE_WITHLABELS');}; bf: {ADD: typeof import('@redis/bloom/dist/commands/bloom/ADD'); add: typeof import('@redis/bloom/dist/commands/bloom/ADD'); CARD: typeof import('@redis/bloom/dist/commands/bloom/CARD'); card: typeof import('@redis/bloom/dist/commands/bloom/CARD'); EXISTS: typeof import('@redis/bloom/dist/commands/bloom/EXISTS'); exists: typeof import('@redis/bloom/dist/commands/bloom/EXISTS'); INFO: typeof import('@redis/bloom/dist/commands/bloom/INFO'); info: typeof import('@redis/bloom/dist/commands/bloom/INFO'); INSERT: typeof import('@redis/bloom/dist/commands/bloom/INSERT'); insert: typeof import('@redis/bloom/dist/commands/bloom/INSERT'); LOADCHUNK: typeof import('@redis/bloom/dist/commands/bloom/LOADCHUNK'); loadChunk: typeof import('@redis/bloom/dist/commands/bloom/LOADCHUNK'); MADD: typeof import('@redis/bloom/dist/commands/bloom/MADD'); mAdd: typeof import('@redis/bloom/dist/commands/bloom/MADD'); MEXISTS: typeof import('@redis/bloom/dist/commands/bloom/MEXISTS'); mExists: typeof import('@redis/bloom/dist/commands/bloom/MEXISTS'); RESERVE: typeof import('@redis/bloom/dist/commands/bloom/RESERVE'); reserve: typeof import('@redis/bloom/dist/commands/bloom/RESERVE'); SCANDUMP: typeof import('@redis/bloom/dist/commands/bloom/SCANDUMP'); scanDump: typeof import('@redis/bloom/dist/commands/bloom/SCANDUMP');}; cms: {INCRBY: typeof import('@redis/bloom/dist/commands/count-min-sketch/INCRBY'); incrBy: typeof import('@redis/bloom/dist/commands/count-min-sketch/INCRBY'); INFO: typeof import('@redis/bloom/dist/commands/count-min-sketch/INFO'); info: typeof import('@redis/bloom/dist/commands/count-min-sketch/INFO'); INITBYDIM: typeof import('@redis/bloom/dist/commands/count-min-sketch/INITBYDIM'); initByDim: typeof import('@redis/bloom/dist/commands/count-min-sketch/INITBYDIM'); INITBYPROB: typeof import('@redis/bloom/dist/commands/count-min-sketch/INITBYPROB'); initByProb: typeof import('@redis/bloom/dist/commands/count-min-sketch/INITBYPROB'); MERGE: typeof import('@redis/bloom/dist/commands/count-min-sketch/MERGE'); merge: typeof import('@redis/bloom/dist/commands/count-min-sketch/MERGE'); QUERY: typeof import('@redis/bloom/dist/commands/count-min-sketch/QUERY'); query: typeof import('@redis/bloom/dist/commands/count-min-sketch/QUERY');}; cf: {ADD: typeof import('@redis/bloom/dist/commands/cuckoo/ADD'); add: typeof import('@redis/bloom/dist/commands/cuckoo/ADD'); ADDNX: typeof import('@redis/bloom/dist/commands/cuckoo/ADDNX'); addNX: typeof import('@redis/bloom/dist/commands/cuckoo/ADDNX'); COUNT: typeof import('@redis/bloom/dist/commands/cuckoo/COUNT'); count: typeof import('@redis/bloom/dist/commands/cuckoo/COUNT'); DEL: typeof import('@redis/bloom/dist/commands/cuckoo/DEL'); del: typeof import('@redis/bloom/dist/commands/cuckoo/DEL'); EXISTS: typeof import('@redis/bloom/dist/commands/cuckoo/EXISTS'); exists: typeof import('@redis/bloom/dist/commands/cuckoo/EXISTS'); INFO: typeof import('@redis/bloom/dist/commands/cuckoo/INFO'); info: typeof import('@redis/bloom/dist/commands/cuckoo/INFO'); INSERT: typeof import('@redis/bloom/dist/commands/cuckoo/INSERT'); insert: typeof import('@redis/bloom/dist/commands/cuckoo/INSERT'); INSERTNX: typeof import('@redis/bloom/dist/commands/cuckoo/INSERTNX'); insertNX: typeof import('@redis/bloom/dist/commands/cuckoo/INSERTNX'); LOADCHUNK: typeof import('@redis/bloom/dist/commands/cuckoo/LOADCHUNK'); loadChunk: typeof import('@redis/bloom/dist/commands/cuckoo/LOADCHUNK'); RESERVE: typeof import('@redis/bloom/dist/commands/cuckoo/RESERVE'); reserve: typeof import('@redis/bloom/dist/commands/cuckoo/RESERVE'); SCANDUMP: typeof import('@redis/bloom/dist/commands/cuckoo/SCANDUMP'); scanDump: typeof import('@redis/bloom/dist/commands/cuckoo/SCANDUMP');}; tDigest: {ADD: typeof import('@redis/bloom/dist/commands/t-digest/ADD'); add: typeof import('@redis/bloom/dist/commands/t-digest/ADD'); BYRANK: typeof import('@redis/bloom/dist/commands/t-digest/BYRANK'); byRank: typeof import('@redis/bloom/dist/commands/t-digest/BYRANK'); BYREVRANK: typeof import('@redis/bloom/dist/commands/t-digest/BYREVRANK'); byRevRank: typeof import('@redis/bloom/dist/commands/t-digest/BYREVRANK'); CDF: typeof import('@redis/bloom/dist/commands/t-digest/CDF'); cdf: typeof import('@redis/bloom/dist/commands/t-digest/CDF'); CREATE: typeof import('@redis/bloom/dist/commands/t-digest/CREATE'); create: typeof import('@redis/bloom/dist/commands/t-digest/CREATE'); INFO: typeof import('@redis/bloom/dist/commands/t-digest/INFO'); info: typeof import('@redis/bloom/dist/commands/t-digest/INFO'); MAX: typeof import('@redis/bloom/dist/commands/t-digest/MAX'); max: typeof import('@redis/bloom/dist/commands/t-digest/MAX'); MERGE: typeof import('@redis/bloom/dist/commands/t-digest/MERGE'); merge: typeof import('@redis/bloom/dist/commands/t-digest/MERGE'); MIN: typeof import('@redis/bloom/dist/commands/t-digest/MIN'); min: typeof import('@redis/bloom/dist/commands/t-digest/MIN'); QUANTILE: typeof import('@redis/bloom/dist/commands/t-digest/QUANTILE'); quantile: typeof import('@redis/bloom/dist/commands/t-digest/QUANTILE'); RANK: typeof import('@redis/bloom/dist/commands/t-digest/RANK'); rank: typeof import('@redis/bloom/dist/commands/t-digest/RANK'); RESET: typeof import('@redis/bloom/dist/commands/t-digest/RESET'); reset: typeof import('@redis/bloom/dist/commands/t-digest/RESET'); REVRANK: typeof import('@redis/bloom/dist/commands/t-digest/REVRANK'); revRank: typeof import('@redis/bloom/dist/commands/t-digest/REVRANK'); TRIMMED_MEAN: typeof import('@redis/bloom/dist/commands/t-digest/TRIMMED_MEAN'); trimmedMean: typeof import('@redis/bloom/dist/commands/t-digest/TRIMMED_MEAN');}; topK: {ADD: typeof import('@redis/bloom/dist/commands/top-k/ADD'); add: typeof import('@redis/bloom/dist/commands/top-k/ADD'); COUNT: typeof import('@redis/bloom/dist/commands/top-k/COUNT'); count: typeof import('@redis/bloom/dist/commands/top-k/COUNT'); INCRBY: typeof import('@redis/bloom/dist/commands/top-k/INCRBY'); incrBy: typeof import('@redis/bloom/dist/commands/top-k/INCRBY'); INFO: typeof import('@redis/bloom/dist/commands/top-k/INFO'); info: typeof import('@redis/bloom/dist/commands/top-k/INFO'); LIST_WITHCOUNT: typeof import('@redis/bloom/dist/commands/top-k/LIST_WITHCOUNT'); listWithCount: typeof import('@redis/bloom/dist/commands/top-k/LIST_WITHCOUNT'); LIST: typeof import('@redis/bloom/dist/commands/top-k/LIST'); list: typeof import('@redis/bloom/dist/commands/top-k/LIST'); QUERY: typeof import('@redis/bloom/dist/commands/top-k/QUERY'); query: typeof import('@redis/bloom/dist/commands/top-k/QUERY'); RESERVE: typeof import('@redis/bloom/dist/commands/top-k/RESERVE'); reserve: typeof import('@redis/bloom/dist/commands/top-k/RESERVE');};} & RedisModules, RedisFunctions, RedisScripts> | null;
|
|
48
|
-
constructor(settings:Settings) {
|
|
49
|
-
super();
|
|
50
|
-
this._client = null;
|
|
51
|
-
this.settings = settings || {};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get isAsync() { return true; }
|
|
55
|
-
|
|
56
|
-
async init() {
|
|
57
|
-
this._client = createClient({url: this.settings.url});
|
|
58
|
-
if (this._client) {
|
|
59
|
-
await this._client.connect();
|
|
60
|
-
await this._client.ping();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async get(key:string) {
|
|
65
|
-
if (this._client == null) return null;
|
|
66
|
-
return await this._client.get(key);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async findKeys(key:string, notKey:string) {
|
|
70
|
-
if (this._client == null) return null;
|
|
71
|
-
const [type] = /^([^:*]+):\*$/.exec(key) || [];
|
|
72
|
-
if (type != null && ['*:*:*', `${key}:*`].includes(notKey)) {
|
|
73
|
-
// Performance optimization for a common Etherpad case.
|
|
74
|
-
return await this._client.sMembers(`ueberDB:keys:${type}`);
|
|
75
|
-
}
|
|
76
|
-
let keys = await this._client.keys(key.replace(/[?[\]\\]/g, '\\$&'));
|
|
77
|
-
if (notKey != null) {
|
|
78
|
-
const regex = this.createFindRegex(key, notKey);
|
|
79
|
-
keys = keys.filter((k:string) => regex.test(k));
|
|
80
|
-
}
|
|
81
|
-
return keys;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async set(key:string, value:string) {
|
|
85
|
-
if (this._client == null) return null;
|
|
86
|
-
const matches = /^([^:]+):([^:]+)$/.exec(key);
|
|
87
|
-
await Promise.all([
|
|
88
|
-
matches && this._client.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]),
|
|
89
|
-
this._client.set(key, value),
|
|
90
|
-
]);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async remove(key:string) {
|
|
94
|
-
if (this._client == null) return null;
|
|
95
|
-
const matches = /^([^:]+):([^:]+)$/.exec(key);
|
|
96
|
-
await Promise.all([
|
|
97
|
-
matches && this._client.sRem(`ueberDB:keys:${matches[1]}`, matches[0]),
|
|
98
|
-
this._client.del(key),
|
|
99
|
-
]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async doBulk(bulk: BulkObject[]) {
|
|
103
|
-
if (this._client == null) return null;
|
|
104
|
-
const multi = this._client.multi();
|
|
105
|
-
|
|
106
|
-
for (const {key, type, value} of bulk) {
|
|
107
|
-
const matches = /^([^:]+):([^:]+)$/.exec(key);
|
|
108
|
-
if (type === 'set') {
|
|
109
|
-
if (matches) {
|
|
110
|
-
multi.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]);
|
|
111
|
-
}
|
|
112
|
-
multi.set(key, value as string);
|
|
113
|
-
} else if (type === 'remove') {
|
|
114
|
-
if (matches) {
|
|
115
|
-
multi.sRem(`ueberDB:keys:${matches[1]}`, matches[0]);
|
|
116
|
-
}
|
|
117
|
-
multi.del(key);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
await multi.exec();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async close() {
|
|
125
|
-
if (this._client == null) return null;
|
|
126
|
-
await this._client.quit();
|
|
127
|
-
this._client = null;
|
|
128
|
-
}
|
|
129
|
-
};
|