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,140 +1,138 @@
1
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
- /**
8
- * 2011 Peter 'Pita' Martischka
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
- let SQDB;
23
- try {
24
- SQDB = require('sqlite3').Database;
25
- }
26
- catch (err) {
27
- throw new Error('sqlite3 not found. It was removed from ueberdb\'s dependencies because it requires ' +
28
- 'compilation which fails on several systems. If you still want to use sqlite, run ' +
29
- '"npm install sqlite3" in your etherpad-lite ./src directory.');
30
- }
31
- const AbstractDatabase_1 = __importDefault(require("../lib/AbstractDatabase"));
32
- const util_1 = __importDefault(require("util"));
33
- const escape = (val) => `'${val.replace(/'/g, "''")}'`;
34
- const Database = class SQLiteDB extends AbstractDatabase_1.default {
35
- db;
36
- constructor(settings) {
37
- super();
38
- this.db = null;
39
- if (!settings || !settings.filename) {
40
- settings = { filename: ':memory:' };
41
- }
42
- this.settings = settings;
43
- // set settings for the dbWrapper
44
- if (settings.filename === ':memory:') {
45
- this.settings.cache = 0;
46
- this.settings.writeInterval = 0;
47
- this.settings.json = true;
48
- }
49
- else {
50
- this.settings.cache = 1000;
51
- this.settings.writeInterval = 100;
52
- this.settings.json = true;
53
- }
54
- }
55
- init(callback) {
56
- util_1.default.callbackify(async () => {
57
- this.db = new SQDB(this.settings.filename);
58
- await this._query('CREATE TABLE IF NOT EXISTS store (key TEXT PRIMARY KEY, value TEXT)');
59
- // @ts-ignore
60
- })(callback);
61
- }
62
- async _query(sql, params = []) {
63
- // It is unclear how util.promisify() deals with variadic functions, so it is not used here.
64
- return await new Promise((resolve, reject) => {
65
- // According to sqlite3's documentation, .run() method (and maybe .all() and .get(); the
66
- // documentation is unclear) might call the callback multiple times. That's OK -- ECMAScript
67
- // guarantees that it is safe to call a Promise executor's resolve and reject functions
68
- // multiple times. The subsequent calls are ignored, except Node.js's 'process' object emits a
69
- // 'multipleResolves' event to aid in debugging.
70
- this.db && this.db.all(sql, params, (err, rows) => {
71
- if (err != null)
72
- return reject(err);
73
- resolve(rows);
74
- });
75
- });
76
- }
77
- // Temporary callbackified version of _query. This will be removed once all database objects are
78
- // asyncified.
79
- _queryCb(sql, params, callback) {
80
- // It is unclear how util.callbackify() handles optional parameters, so it is not used here.
81
- const p = this._query(sql, params);
82
- if (callback)
83
- p.then((rows) => callback(null, rows), (err) => callback(err || new Error(err)));
84
- }
85
- get(key, callback) {
86
- this._queryCb('SELECT value FROM store WHERE key = ?', [key], (err, rows) => callback(err, err == null && rows && rows.length ? rows[0].value : null));
87
- }
88
- findKeys(key, notKey, callback) {
89
- let query = 'SELECT key FROM store WHERE key LIKE ?';
90
- const params = [];
91
- // desired keys are %key:%, e.g. pad:%
92
- key = key.replace(/\*/g, '%');
93
- params.push(key);
94
- if (notKey != null) {
95
- // not desired keys are notKey:%, e.g. %:%:%
96
- notKey = notKey.replace(/\*/g, '%');
97
- query += ' AND key NOT LIKE ?';
98
- params.push(notKey);
99
- }
100
- this._queryCb(query, params, (err, results) => {
101
- const value = [];
102
- if (!err && Object.keys(results).length > 0) {
103
- results.forEach((val) => {
104
- value.push(val.key);
105
- });
106
- }
107
- callback(err, value);
108
- });
109
- }
110
- set(key, value, callback) {
111
- this._queryCb('REPLACE INTO store VALUES (?,?)', [key, value], callback);
112
- }
113
- remove(key, callback) {
114
- this._queryCb('DELETE FROM store WHERE key = ?', [key], callback);
115
- }
116
- doBulk(bulk, callback) {
117
- let sql = 'BEGIN TRANSACTION;\n';
118
- for (const i in bulk) {
119
- if (bulk[i].type === 'set') {
120
- sql += `REPLACE INTO store VALUES (${escape(bulk[i].key)}, ${escape(bulk[i].value)});\n`;
121
- }
122
- else if (bulk[i].type === 'remove') {
123
- sql += `DELETE FROM store WHERE key = ${escape(bulk[i].key)};\n`;
124
- }
125
- }
126
- sql += 'END TRANSACTION;';
127
- this.db && this.db.exec(sql, (err) => {
128
- if (err) {
129
- console.error('ERROR WITH SQL: ');
130
- console.error(sql);
131
- }
132
- callback(err);
133
- });
134
- }
135
- close(callback) {
136
- callback();
137
- this.db && this.db.close((err) => callback(err));
138
- }
2
+
3
+ var AbstractDatabase = require('../lib/AbstractDatabase.js');
4
+ var util = require('util');
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
+ let SQDB;
22
+ try {
23
+ SQDB = require('sqlite3').Database;
24
+ }
25
+ catch (err) {
26
+ throw new Error('sqlite3 not found. It was removed from ueberdb\'s dependencies because it requires ' +
27
+ 'compilation which fails on several systems. If you still want to use sqlite, run ' +
28
+ '"npm install sqlite3" in your etherpad-lite ./src directory.');
29
+ }
30
+ const escape = (val) => `'${val.replace(/'/g, "''")}'`;
31
+ const Database = class SQLiteDB extends AbstractDatabase {
32
+ db;
33
+ constructor(settings) {
34
+ super();
35
+ this.db = null;
36
+ if (!settings || !settings.filename) {
37
+ settings = { filename: ':memory:' };
38
+ }
39
+ this.settings = settings;
40
+ // set settings for the dbWrapper
41
+ if (settings.filename === ':memory:') {
42
+ this.settings.cache = 0;
43
+ this.settings.writeInterval = 0;
44
+ this.settings.json = true;
45
+ }
46
+ else {
47
+ this.settings.cache = 1000;
48
+ this.settings.writeInterval = 100;
49
+ this.settings.json = true;
50
+ }
51
+ }
52
+ init(callback) {
53
+ util.callbackify(async () => {
54
+ this.db = new SQDB(this.settings.filename);
55
+ await this._query('CREATE TABLE IF NOT EXISTS store (key TEXT PRIMARY KEY, value TEXT)');
56
+ // @ts-ignore
57
+ })(callback);
58
+ }
59
+ async _query(sql, params = []) {
60
+ // It is unclear how util.promisify() deals with variadic functions, so it is not used here.
61
+ return await new Promise((resolve, reject) => {
62
+ // According to sqlite3's documentation, .run() method (and maybe .all() and .get(); the
63
+ // documentation is unclear) might call the callback multiple times. That's OK -- ECMAScript
64
+ // guarantees that it is safe to call a Promise executor's resolve and reject functions
65
+ // multiple times. The subsequent calls are ignored, except Node.js's 'process' object emits a
66
+ // 'multipleResolves' event to aid in debugging.
67
+ this.db && this.db.all(sql, params, (err, rows) => {
68
+ if (err != null)
69
+ return reject(err);
70
+ resolve(rows);
71
+ });
72
+ });
73
+ }
74
+ // Temporary callbackified version of _query. This will be removed once all database objects are
75
+ // asyncified.
76
+ _queryCb(sql, params, callback) {
77
+ // It is unclear how util.callbackify() handles optional parameters, so it is not used here.
78
+ const p = this._query(sql, params);
79
+ if (callback)
80
+ p.then((rows) => callback(null, rows), (err) => callback(err || new Error(err)));
81
+ }
82
+ get(key, callback) {
83
+ this._queryCb('SELECT value FROM store WHERE key = ?', [key], (err, rows) => callback(err, err == null && rows && rows.length ? rows[0].value : null));
84
+ }
85
+ findKeys(key, notKey, callback) {
86
+ let query = 'SELECT key FROM store WHERE key LIKE ?';
87
+ const params = [];
88
+ // desired keys are %key:%, e.g. pad:%
89
+ key = key.replace(/\*/g, '%');
90
+ params.push(key);
91
+ if (notKey != null) {
92
+ // not desired keys are notKey:%, e.g. %:%:%
93
+ notKey = notKey.replace(/\*/g, '%');
94
+ query += ' AND key NOT LIKE ?';
95
+ params.push(notKey);
96
+ }
97
+ this._queryCb(query, params, (err, results) => {
98
+ const value = [];
99
+ if (!err && Object.keys(results).length > 0) {
100
+ results.forEach((val) => {
101
+ value.push(val.key);
102
+ });
103
+ }
104
+ callback(err, value);
105
+ });
106
+ }
107
+ set(key, value, callback) {
108
+ this._queryCb('REPLACE INTO store VALUES (?,?)', [key, value], callback);
109
+ }
110
+ remove(key, callback) {
111
+ this._queryCb('DELETE FROM store WHERE key = ?', [key], callback);
112
+ }
113
+ doBulk(bulk, callback) {
114
+ let sql = 'BEGIN TRANSACTION;\n';
115
+ for (const i in bulk) {
116
+ if (bulk[i].type === 'set') {
117
+ sql += `REPLACE INTO store VALUES (${escape(bulk[i].key)}, ${escape(bulk[i].value)});\n`;
118
+ }
119
+ else if (bulk[i].type === 'remove') {
120
+ sql += `DELETE FROM store WHERE key = ${escape(bulk[i].key)};\n`;
121
+ }
122
+ }
123
+ sql += 'END TRANSACTION;';
124
+ this.db && this.db.exec(sql, (err) => {
125
+ if (err) {
126
+ console.error('ERROR WITH SQL: ');
127
+ console.error(sql);
128
+ }
129
+ callback(err);
130
+ });
131
+ }
132
+ close(callback) {
133
+ callback();
134
+ this.db && this.db.close((err) => callback(err));
135
+ }
139
136
  };
137
+
140
138
  exports.Database = Database;