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,40 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
this.emit('
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this.emit('
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.emit('
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
this.emit('
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this.emit('
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
this.emit('
|
|
35
|
-
}
|
|
36
|
-
set(key, value, cb) {
|
|
37
|
-
this.emit('set', key, value, cb);
|
|
38
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var events = require('events');
|
|
4
|
+
|
|
5
|
+
const Database = class extends events.EventEmitter {
|
|
6
|
+
settings;
|
|
7
|
+
constructor(settings) {
|
|
8
|
+
super();
|
|
9
|
+
this.settings = {
|
|
10
|
+
writeInterval: 1,
|
|
11
|
+
...settings,
|
|
12
|
+
};
|
|
13
|
+
settings.mock = this;
|
|
14
|
+
}
|
|
15
|
+
close(cb) {
|
|
16
|
+
this.emit('close', cb);
|
|
17
|
+
}
|
|
18
|
+
doBulk(ops, cb) {
|
|
19
|
+
this.emit('doBulk', ops, cb);
|
|
20
|
+
}
|
|
21
|
+
findKeys(key, notKey, cb) {
|
|
22
|
+
this.emit('findKeys', key, notKey, cb);
|
|
23
|
+
}
|
|
24
|
+
get(key, cb) {
|
|
25
|
+
this.emit('get', key, cb);
|
|
26
|
+
}
|
|
27
|
+
init(cb) {
|
|
28
|
+
this.emit('init', cb);
|
|
29
|
+
}
|
|
30
|
+
remove(key, cb) {
|
|
31
|
+
this.emit('remove', key, cb);
|
|
32
|
+
}
|
|
33
|
+
set(key, value, cb) {
|
|
34
|
+
this.emit('set', key, value, cb);
|
|
35
|
+
}
|
|
39
36
|
};
|
|
37
|
+
|
|
40
38
|
exports.Database = Database;
|
|
@@ -1,135 +1,133 @@
|
|
|
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
|
-
if (
|
|
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
|
-
callback(
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.
|
|
69
|
-
callback(
|
|
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
|
-
this.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (bulk[i].type === '
|
|
117
|
-
bulkMongo.find({ _id: bulk[i].key }).
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.clearPing();
|
|
132
|
-
this.client.close().then(r => callback(r));
|
|
133
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var AbstractDatabase = require('../lib/AbstractDatabase.js');
|
|
4
|
+
var mongodb = require('mongodb');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 2020 Sylchauf
|
|
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 extends AbstractDatabase {
|
|
22
|
+
interval;
|
|
23
|
+
database;
|
|
24
|
+
client;
|
|
25
|
+
collection;
|
|
26
|
+
constructor(settings) {
|
|
27
|
+
super();
|
|
28
|
+
this.settings = settings;
|
|
29
|
+
if (!this.settings.url)
|
|
30
|
+
throw new Error('You must specify a mongodb url');
|
|
31
|
+
// For backwards compatibility:
|
|
32
|
+
if (this.settings.database == null)
|
|
33
|
+
this.settings.database = this.settings.dbName;
|
|
34
|
+
if (!this.settings.collection)
|
|
35
|
+
this.settings.collection = 'ueberdb';
|
|
36
|
+
}
|
|
37
|
+
clearPing() {
|
|
38
|
+
if (this.interval) {
|
|
39
|
+
clearInterval(this.interval);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
schedulePing() {
|
|
43
|
+
this.clearPing();
|
|
44
|
+
this.interval = setInterval(() => {
|
|
45
|
+
this.database.command({
|
|
46
|
+
ping: 1,
|
|
47
|
+
});
|
|
48
|
+
}, 10000);
|
|
49
|
+
}
|
|
50
|
+
init(callback) {
|
|
51
|
+
mongodb.MongoClient.connect(this.settings.url).then((v) => {
|
|
52
|
+
this.client = v;
|
|
53
|
+
this.database = v.db(this.settings.database);
|
|
54
|
+
this.collection = this.database.collection(this.settings.collection);
|
|
55
|
+
callback(null);
|
|
56
|
+
})
|
|
57
|
+
.catch((v) => {
|
|
58
|
+
callback(v);
|
|
59
|
+
});
|
|
60
|
+
this.schedulePing();
|
|
61
|
+
}
|
|
62
|
+
get(key, callback) {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
this.collection.findOne({ _id: key })
|
|
65
|
+
.then((v) => {
|
|
66
|
+
callback(null, v && v.value);
|
|
67
|
+
}).catch(v => {
|
|
68
|
+
console.log(v);
|
|
69
|
+
callback(v);
|
|
70
|
+
});
|
|
71
|
+
this.schedulePing();
|
|
72
|
+
}
|
|
73
|
+
findKeys(key, notKey, callback) {
|
|
74
|
+
const selector = {
|
|
75
|
+
$and: [
|
|
76
|
+
{ _id: { $regex: `${key.replace(/\*/g, '')}` } },
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
if (notKey) {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
selector.$and.push({ _id: { $not: { $regex: `${notKey.replace(/\*/g, '')}` } } });
|
|
82
|
+
}
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
this.collection.find(selector).map((i) => i._id)
|
|
85
|
+
.toArray()
|
|
86
|
+
.then(r => {
|
|
87
|
+
callback(null, r);
|
|
88
|
+
})
|
|
89
|
+
.catch(v => callback(v));
|
|
90
|
+
this.schedulePing();
|
|
91
|
+
}
|
|
92
|
+
set(key, value, callback) {
|
|
93
|
+
if (key.length > 100) {
|
|
94
|
+
callback('Your Key can only be 100 chars');
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
this.collection.updateMany({ _id: key }, { $set: { value } }, { upsert: true })
|
|
99
|
+
.then(v => callback(null)).catch(v => callback(v));
|
|
100
|
+
}
|
|
101
|
+
this.schedulePing();
|
|
102
|
+
}
|
|
103
|
+
remove(key, callback) {
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
this.collection.deleteOne({ _id: key })
|
|
106
|
+
.then(r => callback(null, r))
|
|
107
|
+
.catch(v => callback(v));
|
|
108
|
+
this.schedulePing();
|
|
109
|
+
}
|
|
110
|
+
doBulk(bulk, callback) {
|
|
111
|
+
const bulkMongo = this.collection.initializeOrderedBulkOp();
|
|
112
|
+
for (const i in bulk) {
|
|
113
|
+
if (bulk[i].type === 'set') {
|
|
114
|
+
bulkMongo.find({ _id: bulk[i].key }).upsert().updateOne({ $set: { value: bulk[i].value } });
|
|
115
|
+
}
|
|
116
|
+
else if (bulk[i].type === 'remove') {
|
|
117
|
+
bulkMongo.find({ _id: bulk[i].key }).deleteOne();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
bulkMongo.execute().then((res) => {
|
|
121
|
+
callback(null, res);
|
|
122
|
+
}).catch((error) => {
|
|
123
|
+
callback(error);
|
|
124
|
+
});
|
|
125
|
+
this.schedulePing();
|
|
126
|
+
}
|
|
127
|
+
close(callback) {
|
|
128
|
+
this.clearPing();
|
|
129
|
+
this.client.close().then(r => callback(r));
|
|
130
|
+
}
|
|
134
131
|
};
|
|
132
|
+
|
|
135
133
|
exports.Database = Database;
|