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
|
@@ -1,122 +1,120 @@
|
|
|
1
|
-
|
|
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
|
-
if (this.settings.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
if (this.settings.
|
|
44
|
-
options.
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this._client
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
await this._client.quit();
|
|
119
|
-
this._client = null;
|
|
120
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var AbstractDatabase = require('../lib/AbstractDatabase.js');
|
|
4
|
+
var redis = require('redis');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 2011 Peter 'Pita' Martischka
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
const Database = class RedisDB extends AbstractDatabase {
|
|
22
|
+
_client;
|
|
23
|
+
constructor(settings) {
|
|
24
|
+
super();
|
|
25
|
+
this._client = null;
|
|
26
|
+
this.settings = settings || {};
|
|
27
|
+
}
|
|
28
|
+
get isAsync() { return true; }
|
|
29
|
+
async init() {
|
|
30
|
+
if (this.settings.url) {
|
|
31
|
+
this._client = redis.createClient({ url: this.settings.url });
|
|
32
|
+
}
|
|
33
|
+
else if (this.settings.host) {
|
|
34
|
+
const options = {
|
|
35
|
+
socket: {
|
|
36
|
+
host: this.settings.host,
|
|
37
|
+
port: Number(this.settings.port),
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
if (this.settings.password) {
|
|
41
|
+
options.password = this.settings.password;
|
|
42
|
+
}
|
|
43
|
+
if (this.settings.user) {
|
|
44
|
+
options.username = this.settings.user;
|
|
45
|
+
}
|
|
46
|
+
this._client = redis.createClient(options);
|
|
47
|
+
}
|
|
48
|
+
if (this._client) {
|
|
49
|
+
await this._client.connect();
|
|
50
|
+
await this._client.ping();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async get(key) {
|
|
54
|
+
if (this._client == null)
|
|
55
|
+
return null;
|
|
56
|
+
return await this._client.get(key);
|
|
57
|
+
}
|
|
58
|
+
async findKeys(key, notKey) {
|
|
59
|
+
if (this._client == null)
|
|
60
|
+
return null;
|
|
61
|
+
const [type] = /^([^:*]+):\*$/.exec(key) || [];
|
|
62
|
+
if (type != null && ['*:*:*', `${key}:*`].includes(notKey)) {
|
|
63
|
+
// Performance optimization for a common Etherpad case.
|
|
64
|
+
return await this._client.sMembers(`ueberDB:keys:${type}`);
|
|
65
|
+
}
|
|
66
|
+
let keys = await this._client.keys(key.replace(/[?[\]\\]/g, '\\$&'));
|
|
67
|
+
if (notKey != null) {
|
|
68
|
+
const regex = this.createFindRegex(key, notKey);
|
|
69
|
+
keys = keys.filter((k) => regex.test(k));
|
|
70
|
+
}
|
|
71
|
+
return keys;
|
|
72
|
+
}
|
|
73
|
+
async set(key, value) {
|
|
74
|
+
if (this._client == null)
|
|
75
|
+
return null;
|
|
76
|
+
const matches = /^([^:]+):([^:]+)$/.exec(key);
|
|
77
|
+
await Promise.all([
|
|
78
|
+
matches && this._client.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]),
|
|
79
|
+
this._client.set(key, value),
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
async remove(key) {
|
|
83
|
+
if (this._client == null)
|
|
84
|
+
return null;
|
|
85
|
+
const matches = /^([^:]+):([^:]+)$/.exec(key);
|
|
86
|
+
await Promise.all([
|
|
87
|
+
matches && this._client.sRem(`ueberDB:keys:${matches[1]}`, matches[0]),
|
|
88
|
+
this._client.del(key),
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
async doBulk(bulk) {
|
|
92
|
+
if (this._client == null)
|
|
93
|
+
return null;
|
|
94
|
+
const multi = this._client.multi();
|
|
95
|
+
for (const { key, type, value } of bulk) {
|
|
96
|
+
const matches = /^([^:]+):([^:]+)$/.exec(key);
|
|
97
|
+
if (type === 'set') {
|
|
98
|
+
if (matches) {
|
|
99
|
+
multi.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]);
|
|
100
|
+
}
|
|
101
|
+
multi.set(key, value);
|
|
102
|
+
}
|
|
103
|
+
else if (type === 'remove') {
|
|
104
|
+
if (matches) {
|
|
105
|
+
multi.sRem(`ueberDB:keys:${matches[1]}`, matches[0]);
|
|
106
|
+
}
|
|
107
|
+
multi.del(key);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
await multi.exec();
|
|
111
|
+
}
|
|
112
|
+
async close() {
|
|
113
|
+
if (this._client == null)
|
|
114
|
+
return null;
|
|
115
|
+
await this._client.quit();
|
|
116
|
+
this._client = null;
|
|
117
|
+
}
|
|
121
118
|
};
|
|
119
|
+
|
|
122
120
|
exports.Database = Database;
|
|
@@ -1,123 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!settings.
|
|
36
|
-
settings.
|
|
37
|
-
}
|
|
38
|
-
if (!settings.
|
|
39
|
-
settings.
|
|
40
|
-
}
|
|
41
|
-
if (!settings.
|
|
42
|
-
settings.
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (bulk[i].type === '
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(cb) => {
|
|
106
|
-
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.connection.close(callback);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var AbstractDatabase = require('../lib/AbstractDatabase.js');
|
|
4
|
+
var r = require('rethinkdb');
|
|
5
|
+
var async = require('async');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 2016 Remi Arnaud
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const Database = class extends AbstractDatabase {
|
|
23
|
+
host;
|
|
24
|
+
db;
|
|
25
|
+
port;
|
|
26
|
+
table;
|
|
27
|
+
connection;
|
|
28
|
+
constructor(settings) {
|
|
29
|
+
super();
|
|
30
|
+
if (!settings)
|
|
31
|
+
settings = {};
|
|
32
|
+
if (!settings.host) {
|
|
33
|
+
settings.host = 'localhost';
|
|
34
|
+
}
|
|
35
|
+
if (!settings.port) {
|
|
36
|
+
settings.port = 28015;
|
|
37
|
+
}
|
|
38
|
+
if (!settings.db) {
|
|
39
|
+
settings.db = 'test';
|
|
40
|
+
}
|
|
41
|
+
if (!settings.table) {
|
|
42
|
+
settings.table = 'test';
|
|
43
|
+
}
|
|
44
|
+
this.host = settings.host;
|
|
45
|
+
this.db = settings.db;
|
|
46
|
+
this.port = settings.port;
|
|
47
|
+
this.table = settings.table;
|
|
48
|
+
this.connection = null;
|
|
49
|
+
}
|
|
50
|
+
init(callback) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
r.connect(this, (err, conn) => {
|
|
53
|
+
if (err)
|
|
54
|
+
throw err;
|
|
55
|
+
this.connection = conn;
|
|
56
|
+
r.table(this.table).run(this.connection, (err, cursor) => {
|
|
57
|
+
if (err) {
|
|
58
|
+
// assuming table does not exists
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
r.tableCreate(this.table).run(this.connection, callback);
|
|
61
|
+
}
|
|
62
|
+
else if (callback) {
|
|
63
|
+
callback(null, cursor);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
get(key, callback) {
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
r.table(this.table).get(key).run(this.connection, (err, item) => {
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
callback(err, (item ? item.content : item));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
findKeys(key, notKey, callback) {
|
|
76
|
+
const keys = [];
|
|
77
|
+
const regex = this.createFindRegex(key, notKey);
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
r.filter((item) => {
|
|
80
|
+
if (item.id.search(regex) !== -1) {
|
|
81
|
+
keys.push(item.id);
|
|
82
|
+
}
|
|
83
|
+
}).run(this.connection, callback);
|
|
84
|
+
}
|
|
85
|
+
set(key, value, callback) {
|
|
86
|
+
r.table(this.table)
|
|
87
|
+
.insert({ id: key, content: value }, { conflict: 'replace' })
|
|
88
|
+
.run(this.connection, callback);
|
|
89
|
+
}
|
|
90
|
+
doBulk(bulk, callback) {
|
|
91
|
+
const _in = [];
|
|
92
|
+
const _out = [];
|
|
93
|
+
for (const i in bulk) {
|
|
94
|
+
if (bulk[i].type === 'set') {
|
|
95
|
+
_in.push({ id: bulk[i].key, content: bulk[i].value });
|
|
96
|
+
}
|
|
97
|
+
else if (bulk[i].type === 'remove') {
|
|
98
|
+
_out.push(bulk[i].key);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async.parallel([
|
|
102
|
+
(cb) => {
|
|
103
|
+
r.table(this.table).insert(_in, { conflict: 'replace' }).run(this.connection, cb);
|
|
104
|
+
},
|
|
105
|
+
(cb) => {
|
|
106
|
+
r.table(this.table).getAll(_out).delete().run(this.connection, cb);
|
|
107
|
+
},
|
|
108
|
+
], callback);
|
|
109
|
+
}
|
|
110
|
+
remove(key, callback) {
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
r.table(this.table).get(key).delete().run(this.connection, callback);
|
|
113
|
+
}
|
|
114
|
+
close(callback) {
|
|
115
|
+
if (this.connection) {
|
|
116
|
+
this.connection.close(callback);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
122
119
|
};
|
|
120
|
+
|
|
123
121
|
exports.Database = Database;
|