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.
Files changed (37) hide show
  1. package/dist/databases/cassandra_db.js +233 -235
  2. package/dist/databases/couch_db.js +171 -173
  3. package/dist/databases/dirty_db.js +73 -76
  4. package/dist/databases/dirty_git_db.js +57 -75
  5. package/dist/databases/elasticsearch_db.js +241 -267
  6. package/dist/databases/memory_db.js +35 -37
  7. package/dist/databases/mock_db.js +36 -38
  8. package/dist/databases/mongodb_db.js +131 -133
  9. package/dist/databases/mssql_db.js +183 -185
  10. package/dist/databases/mysql_db.js +166 -168
  11. package/dist/databases/postgres_db.js +188 -190
  12. package/dist/databases/postgrespool_db.js +10 -10
  13. package/dist/databases/redis_db.js +118 -120
  14. package/dist/databases/rethink_db.js +119 -121
  15. package/dist/databases/sqlite_db.js +135 -137
  16. package/dist/index.js +195 -213
  17. package/lib/AbstractDatabase.ts +79 -0
  18. package/lib/CacheAndBufferLayer.ts +665 -0
  19. package/lib/logging.ts +32 -0
  20. package/package.json +16 -12
  21. package/dist/lib/AbstractDatabase.js +0 -38
  22. package/dist/lib/CacheAndBufferLayer.js +0 -657
  23. package/dist/lib/logging.js +0 -34
  24. package/dist/test/lib/databases.js +0 -74
  25. package/dist/test/test.js +0 -327
  26. package/dist/test/test_bulk.js +0 -74
  27. package/dist/test/test_elasticsearch.js +0 -157
  28. package/dist/test/test_findKeys.js +0 -69
  29. package/dist/test/test_flush.js +0 -83
  30. package/dist/test/test_getSub.js +0 -57
  31. package/dist/test/test_lru.js +0 -155
  32. package/dist/test/test_memory.js +0 -59
  33. package/dist/test/test_metrics.js +0 -772
  34. package/dist/test/test_mysql.js +0 -90
  35. package/dist/test/test_postgres.js +0 -40
  36. package/dist/test/test_setSub.js +0 -48
  37. package/dist/test/test_tojson.js +0 -62
@@ -1,40 +1,38 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Database = void 0;
7
- const events_1 = __importDefault(require("events"));
8
- const Database = class extends events_1.default.EventEmitter {
9
- settings;
10
- constructor(settings) {
11
- super();
12
- this.settings = {
13
- writeInterval: 1,
14
- ...settings,
15
- };
16
- settings.mock = this;
17
- }
18
- close(cb) {
19
- this.emit('close', cb);
20
- }
21
- doBulk(ops, cb) {
22
- this.emit('doBulk', ops, cb);
23
- }
24
- findKeys(key, notKey, cb) {
25
- this.emit('findKeys', key, notKey, cb);
26
- }
27
- get(key, cb) {
28
- this.emit('get', key, cb);
29
- }
30
- init(cb) {
31
- this.emit('init', cb);
32
- }
33
- remove(key, cb) {
34
- this.emit('remove', key, cb);
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
- "use strict";
2
- /**
3
- * 2020 Sylchauf
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS-IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.Database = void 0;
22
- const AbstractDatabase_1 = __importDefault(require("../lib/AbstractDatabase"));
23
- const mongodb_1 = require("mongodb");
24
- const Database = class extends AbstractDatabase_1.default {
25
- interval;
26
- database;
27
- client;
28
- collection;
29
- constructor(settings) {
30
- super();
31
- this.settings = settings;
32
- if (!this.settings.url)
33
- throw new Error('You must specify a mongodb url');
34
- // For backwards compatibility:
35
- if (this.settings.database == null)
36
- this.settings.database = this.settings.dbName;
37
- if (!this.settings.collection)
38
- this.settings.collection = 'ueberdb';
39
- }
40
- clearPing() {
41
- if (this.interval) {
42
- clearInterval(this.interval);
43
- }
44
- }
45
- schedulePing() {
46
- this.clearPing();
47
- this.interval = setInterval(() => {
48
- this.database.command({
49
- ping: 1,
50
- });
51
- }, 10000);
52
- }
53
- init(callback) {
54
- mongodb_1.MongoClient.connect(this.settings.url).then((v) => {
55
- this.client = v;
56
- this.database = v.db(this.settings.database);
57
- this.collection = this.database.collection(this.settings.collection);
58
- callback(null);
59
- })
60
- .catch((v) => {
61
- callback(v);
62
- });
63
- this.schedulePing();
64
- }
65
- get(key, callback) {
66
- // @ts-ignore
67
- this.collection.findOne({ _id: key })
68
- .then((v) => {
69
- callback(null, v && v.value);
70
- }).catch(v => {
71
- console.log(v);
72
- callback(v);
73
- });
74
- this.schedulePing();
75
- }
76
- findKeys(key, notKey, callback) {
77
- const selector = {
78
- $and: [
79
- { _id: { $regex: `${key.replace(/\*/g, '')}` } },
80
- ],
81
- };
82
- if (notKey) {
83
- // @ts-ignore
84
- selector.$and.push({ _id: { $not: { $regex: `${notKey.replace(/\*/g, '')}` } } });
85
- }
86
- // @ts-ignore
87
- this.collection.find(selector).map((i) => i._id)
88
- .toArray()
89
- .then(r => {
90
- callback(null, r);
91
- })
92
- .catch(v => callback(v));
93
- this.schedulePing();
94
- }
95
- set(key, value, callback) {
96
- if (key.length > 100) {
97
- callback('Your Key can only be 100 chars');
98
- }
99
- else {
100
- // @ts-ignore
101
- this.collection.updateMany({ _id: key }, { $set: { value } }, { upsert: true })
102
- .then(v => callback(null)).catch(v => callback(v));
103
- }
104
- this.schedulePing();
105
- }
106
- remove(key, callback) {
107
- // @ts-ignore
108
- this.collection.deleteOne({ _id: key })
109
- .then(r => callback(null, r))
110
- .catch(v => callback(v));
111
- this.schedulePing();
112
- }
113
- doBulk(bulk, callback) {
114
- const bulkMongo = this.collection.initializeOrderedBulkOp();
115
- for (const i in bulk) {
116
- if (bulk[i].type === 'set') {
117
- bulkMongo.find({ _id: bulk[i].key }).upsert().updateOne({ $set: { value: bulk[i].value } });
118
- }
119
- else if (bulk[i].type === 'remove') {
120
- bulkMongo.find({ _id: bulk[i].key }).deleteOne();
121
- }
122
- }
123
- bulkMongo.execute().then((res) => {
124
- callback(null, res);
125
- }).catch((error) => {
126
- callback(error);
127
- });
128
- this.schedulePing();
129
- }
130
- close(callback) {
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;