ueberdb2 4.1.8 → 4.1.10
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/databases/cassandra_db.js +233 -235
- package/dist/databases/couch_db.js +171 -173
- package/dist/databases/dirty_db.js +73 -76
- package/dist/databases/dirty_git_db.js +57 -75
- package/dist/databases/elasticsearch_db.js +241 -267
- package/dist/databases/memory_db.js +35 -37
- package/dist/databases/mock_db.js +36 -38
- package/dist/databases/mongodb_db.js +131 -133
- package/dist/databases/mssql_db.js +183 -185
- package/dist/databases/mysql_db.js +166 -168
- package/dist/databases/postgres_db.js +188 -190
- package/dist/databases/postgrespool_db.js +10 -10
- package/dist/databases/redis_db.js +118 -120
- package/dist/databases/rethink_db.js +119 -121
- package/dist/databases/sqlite_db.js +135 -137
- package/dist/index.js +195 -213
- package/lib/AbstractDatabase.ts +79 -0
- package/lib/CacheAndBufferLayer.ts +665 -0
- package/lib/logging.ts +32 -0
- package/package.json +16 -12
- package/dist/lib/AbstractDatabase.js +0 -38
- package/dist/lib/CacheAndBufferLayer.js +0 -657
- package/dist/lib/logging.js +0 -34
- package/dist/test/lib/databases.js +0 -74
- package/dist/test/test.js +0 -327
- package/dist/test/test_bulk.js +0 -74
- package/dist/test/test_elasticsearch.js +0 -157
- package/dist/test/test_findKeys.js +0 -69
- package/dist/test/test_flush.js +0 -83
- package/dist/test/test_getSub.js +0 -57
- package/dist/test/test_lru.js +0 -155
- package/dist/test/test_memory.js +0 -59
- package/dist/test/test_metrics.js +0 -772
- package/dist/test/test_mysql.js +0 -90
- package/dist/test/test_postgres.js +0 -40
- package/dist/test/test_setSub.js +0 -48
- package/dist/test/test_tojson.js +0 -62
package/dist/index.js
CHANGED
|
@@ -1,215 +1,197 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
* @param
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
return this.db.setSub(key, sub, value);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Flushes unwritten changes then closes the connection to the underlying database. After this
|
|
200
|
-
* returns, any future call to a method on this object may result in an error.
|
|
201
|
-
*
|
|
202
|
-
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
|
|
203
|
-
*/
|
|
204
|
-
close(callback = null) {
|
|
205
|
-
if (callback != null) { // @ts-ignore
|
|
206
|
-
return cbDb.close.call(this.db, callback);
|
|
207
|
-
}
|
|
208
|
-
return this.db.close();
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
exports.Database = Database;
|
|
212
|
-
/**
|
|
213
|
-
* Deprecated synonym of Database.
|
|
214
|
-
*/
|
|
2
|
+
|
|
3
|
+
var CacheAndBufferLayer = require('./lib/CacheAndBufferLayer.js');
|
|
4
|
+
var logging = require('./lib/logging.js');
|
|
5
|
+
var util = require('util');
|
|
6
|
+
|
|
7
|
+
const cbDb = {
|
|
8
|
+
init: () => { },
|
|
9
|
+
flush: () => { },
|
|
10
|
+
get: () => { },
|
|
11
|
+
remove: () => { },
|
|
12
|
+
findKeys: () => { },
|
|
13
|
+
close: () => { },
|
|
14
|
+
getSub: () => { },
|
|
15
|
+
setSub: () => { },
|
|
16
|
+
};
|
|
17
|
+
const fns = ['close', 'findKeys', 'flush', 'get', 'getSub', 'init', 'remove', 'set', 'setSub'];
|
|
18
|
+
for (const fn of fns) {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
cbDb[fn] = util.callbackify(CacheAndBufferLayer.Database.prototype[fn]);
|
|
21
|
+
}
|
|
22
|
+
const makeDoneCallback = (callback, deprecated) => (err) => {
|
|
23
|
+
if (callback)
|
|
24
|
+
callback(err);
|
|
25
|
+
if (deprecated)
|
|
26
|
+
deprecated(err);
|
|
27
|
+
if (err != null && callback == null && deprecated == null)
|
|
28
|
+
throw err;
|
|
29
|
+
};
|
|
30
|
+
const Database = class {
|
|
31
|
+
type;
|
|
32
|
+
dbModule;
|
|
33
|
+
dbSettings;
|
|
34
|
+
wrapperSettings;
|
|
35
|
+
logger;
|
|
36
|
+
db;
|
|
37
|
+
metrics;
|
|
38
|
+
/**
|
|
39
|
+
* @param type The type of the database
|
|
40
|
+
* @param dbSettings The settings for that specific database type
|
|
41
|
+
* @param wrapperSettings
|
|
42
|
+
* @param logger Optional logger object. If no logger object is provided no logging will occur.
|
|
43
|
+
* The logger object is expected to be a log4js logger object or `console`. A logger object
|
|
44
|
+
* from another logging library should also work, but performance may be reduced if the logger
|
|
45
|
+
* object does not have is${Level}Enabled() methods (isDebugEnabled(), etc.).
|
|
46
|
+
*/
|
|
47
|
+
constructor(type, dbSettings, wrapperSettings, logger = null) {
|
|
48
|
+
if (!type) {
|
|
49
|
+
type = 'sqlite';
|
|
50
|
+
dbSettings = null;
|
|
51
|
+
wrapperSettings = null;
|
|
52
|
+
}
|
|
53
|
+
// saves all settings and require the db module
|
|
54
|
+
this.type = type;
|
|
55
|
+
this.dbModule = require(`./databases/${type}_db`);
|
|
56
|
+
this.dbSettings = dbSettings;
|
|
57
|
+
this.wrapperSettings = wrapperSettings;
|
|
58
|
+
this.logger = logging.normalizeLogger(logger);
|
|
59
|
+
const db = new this.dbModule.Database(this.dbSettings);
|
|
60
|
+
db.logger = this.logger;
|
|
61
|
+
this.db = new CacheAndBufferLayer.Database(db, this.wrapperSettings, this.logger);
|
|
62
|
+
// Expose the cache wrapper's metrics to the user. See lib/CacheAndBufferLayer.js for details.
|
|
63
|
+
//
|
|
64
|
+
// WARNING: This feature is EXPERIMENTAL -- do not assume it will continue to exist in its
|
|
65
|
+
// current form in a future version.
|
|
66
|
+
this.metrics = this.db.metrics;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
|
|
70
|
+
*/
|
|
71
|
+
init(callback = null) {
|
|
72
|
+
if (callback != null) {
|
|
73
|
+
return cbDb.init.call(this.db);
|
|
74
|
+
}
|
|
75
|
+
return this.db.init();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Wrapper functions
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* Deprecated synonym of flush().
|
|
82
|
+
*
|
|
83
|
+
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
|
|
84
|
+
*/
|
|
85
|
+
doShutdown(callback = null) {
|
|
86
|
+
return this.flush(callback);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Writes any unsaved changes to the underlying database.
|
|
90
|
+
*
|
|
91
|
+
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
|
|
92
|
+
*/
|
|
93
|
+
flush(callback = null) {
|
|
94
|
+
if (!cbDb || !cbDb.flush === undefined)
|
|
95
|
+
return null;
|
|
96
|
+
if (callback != null) { // @ts-ignore
|
|
97
|
+
return cbDb.flush.call(this.db, callback);
|
|
98
|
+
}
|
|
99
|
+
return this.db.flush();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @param key
|
|
103
|
+
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
|
|
104
|
+
*/
|
|
105
|
+
get(key, callback = null) {
|
|
106
|
+
if (callback != null) { // @ts-ignore
|
|
107
|
+
return cbDb.get.call(this.db, key, callback);
|
|
108
|
+
}
|
|
109
|
+
return this.db.get(key);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @param key
|
|
113
|
+
* @param notKey
|
|
114
|
+
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
|
|
115
|
+
*/
|
|
116
|
+
findKeys(key, notKey, callback = null) {
|
|
117
|
+
if (callback != null) { // @ts-ignore
|
|
118
|
+
return cbDb.findKeys.call(this.db, key, notKey, callback);
|
|
119
|
+
}
|
|
120
|
+
return this.db.findKeys(key, notKey);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Removes an entry from the database if present.
|
|
124
|
+
*
|
|
125
|
+
* @param key
|
|
126
|
+
* @param cb Deprecated. Node-style callback. Called when the write has been committed to the
|
|
127
|
+
* underlying database driver. If null, a Promise is returned.
|
|
128
|
+
* @param deprecated Deprecated callback that is called just after cb. Ignored if cb is null.
|
|
129
|
+
*/
|
|
130
|
+
remove(key, cb = null, deprecated = null) {
|
|
131
|
+
if (cb != null) { // @ts-ignore
|
|
132
|
+
return cbDb.remove.call(this.db, key, makeDoneCallback(cb, deprecated));
|
|
133
|
+
}
|
|
134
|
+
return this.db.remove(key);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Adds or changes the value of an entry.
|
|
138
|
+
*
|
|
139
|
+
* @param key
|
|
140
|
+
* @param value
|
|
141
|
+
* @param cb Deprecated. Node-style callback. Called when the write has been committed to the
|
|
142
|
+
* underlying database driver. If null, a Promise is returned.
|
|
143
|
+
* @param deprecated Deprecated callback that is called just after cb. Ignored if cb is null.
|
|
144
|
+
*/
|
|
145
|
+
set(key, value, cb = null, deprecated = null) {
|
|
146
|
+
if (cb != null) { // @ts-ignore
|
|
147
|
+
return cbDb.get.call(this.db, key, value, makeDoneCallback(cb, deprecated));
|
|
148
|
+
}
|
|
149
|
+
return this.db.set(key, value);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @param key
|
|
153
|
+
* @param sub
|
|
154
|
+
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
|
|
155
|
+
*/
|
|
156
|
+
getSub(key, sub, callback = null) {
|
|
157
|
+
if (callback != null) { // @ts-ignore
|
|
158
|
+
return cbDb.getSub.call(this.db, key, sub, callback);
|
|
159
|
+
}
|
|
160
|
+
return this.db.getSub(key, sub);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Adds or changes a subvalue of an entry.
|
|
164
|
+
*
|
|
165
|
+
* @param key
|
|
166
|
+
* @param sub
|
|
167
|
+
* @param value
|
|
168
|
+
* @param cb Deprecated. Node-style callback. Called when the write has been committed to the
|
|
169
|
+
* underlying database driver. If null, a Promise is returned.
|
|
170
|
+
* @param deprecated Deprecated callback that is called just after cb. Ignored if cb is null.
|
|
171
|
+
*/
|
|
172
|
+
setSub(key, sub, value, cb = null, deprecated = null) {
|
|
173
|
+
if (cb != null) {
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
return cbDb.setSub.call(this.db, key, sub, value, makeDoneCallback(cb, deprecated));
|
|
176
|
+
}
|
|
177
|
+
return this.db.setSub(key, sub, value);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Flushes unwritten changes then closes the connection to the underlying database. After this
|
|
181
|
+
* returns, any future call to a method on this object may result in an error.
|
|
182
|
+
*
|
|
183
|
+
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
|
|
184
|
+
*/
|
|
185
|
+
close(callback = null) {
|
|
186
|
+
if (callback != null) { // @ts-ignore
|
|
187
|
+
return cbDb.close.call(this.db, callback);
|
|
188
|
+
}
|
|
189
|
+
return this.db.close();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Deprecated synonym of Database.
|
|
194
|
+
*/
|
|
215
195
|
exports.database = exports.Database;
|
|
196
|
+
|
|
197
|
+
exports.Database = Database;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {normalizeLogger} from './logging';
|
|
2
|
+
|
|
3
|
+
const nullLogger = normalizeLogger(null);
|
|
4
|
+
|
|
5
|
+
// Format: All characters match themselves except * matches any zero or more characters. No
|
|
6
|
+
// backslash escaping is supported, so it is impossible to create a pattern that matches only the
|
|
7
|
+
// '*' character.
|
|
8
|
+
const simpleGlobToRegExp = (s:string) => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
9
|
+
|
|
10
|
+
export type Settings = {
|
|
11
|
+
data?: any;
|
|
12
|
+
table?: string;
|
|
13
|
+
db?: string;
|
|
14
|
+
idleTimeoutMillis?: any;
|
|
15
|
+
min?: any;
|
|
16
|
+
max?: any;
|
|
17
|
+
engine?: string;
|
|
18
|
+
charset?: string;
|
|
19
|
+
server?: string | undefined;
|
|
20
|
+
requestTimeout?: number;
|
|
21
|
+
bulkLimit?: number;
|
|
22
|
+
queryTimeout?: number;
|
|
23
|
+
connectionString?: string;
|
|
24
|
+
parseJSON?: boolean;
|
|
25
|
+
dbName?: string;
|
|
26
|
+
collection?: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
mock?: any;
|
|
29
|
+
base_index?: string;
|
|
30
|
+
migrate_to_newer_schema?: boolean;
|
|
31
|
+
api?: string
|
|
32
|
+
filename?: string;
|
|
33
|
+
database?: string;
|
|
34
|
+
password?: string;
|
|
35
|
+
user?: string;
|
|
36
|
+
port?: number | string;
|
|
37
|
+
host?: string;
|
|
38
|
+
maxListeners?: number | undefined;
|
|
39
|
+
json?: boolean;
|
|
40
|
+
cache?: number;
|
|
41
|
+
writeInterval?: number;
|
|
42
|
+
logger?: any;
|
|
43
|
+
columnFamily?: any;
|
|
44
|
+
clientOptions?: any;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class AbstractDatabase {
|
|
49
|
+
logger: any;
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
settings: Settings;
|
|
52
|
+
constructor() {
|
|
53
|
+
if (new.target === module.exports) {
|
|
54
|
+
throw new TypeError('cannot instantiate Abstract Database directly');
|
|
55
|
+
}
|
|
56
|
+
for (const fn of ['init', 'close', 'get', 'findKeys', 'remove', 'set']) {
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
if (typeof this[fn] !== 'function') throw new TypeError(`method ${fn} not defined`);
|
|
59
|
+
}
|
|
60
|
+
this.logger = nullLogger;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* For findKey regex. Used by document dbs like mongodb or dirty.
|
|
65
|
+
*/
|
|
66
|
+
createFindRegex(key:string, notKey?:string) {
|
|
67
|
+
let regex = `^(?=${simpleGlobToRegExp(key)}$)`;
|
|
68
|
+
if (notKey != null) regex += `(?!${simpleGlobToRegExp(notKey)}$)`;
|
|
69
|
+
return new RegExp(regex);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
doBulk(operations:any, cb: ()=>{}) {
|
|
73
|
+
throw new Error('the doBulk method must be implemented if write caching is enabled');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get isAsync() { return false; }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default AbstractDatabase;
|