@sprucelabs/postgres-data-store 4.1.14 → 4.1.16
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.
|
@@ -44,12 +44,13 @@ class PostgresDatabase {
|
|
|
44
44
|
: `${this.idCount++}`;
|
|
45
45
|
}
|
|
46
46
|
async update(collection, query, updates) {
|
|
47
|
+
var _a;
|
|
47
48
|
const { sql, values } = this.queries.update(collection, query, updates, false);
|
|
48
49
|
const results = await this.client.query({
|
|
49
50
|
text: sql,
|
|
50
51
|
values,
|
|
51
52
|
});
|
|
52
|
-
return results.rowCount;
|
|
53
|
+
return (_a = results.rowCount) !== null && _a !== void 0 ? _a : 0;
|
|
53
54
|
}
|
|
54
55
|
async count(collection, query) {
|
|
55
56
|
const { sql, values } = this.queries.find(collection, query !== null && query !== void 0 ? query : {}, {
|
|
@@ -99,12 +100,13 @@ class PostgresDatabase {
|
|
|
99
100
|
return (_a = results[0]) !== null && _a !== void 0 ? _a : null;
|
|
100
101
|
}
|
|
101
102
|
async delete(collection, query) {
|
|
103
|
+
var _a;
|
|
102
104
|
const { sql, values } = this.queries.delete(collection, query);
|
|
103
105
|
const results = await this.client.query({
|
|
104
106
|
text: sql,
|
|
105
107
|
values,
|
|
106
108
|
});
|
|
107
|
-
return results.rowCount;
|
|
109
|
+
return (_a = results.rowCount) !== null && _a !== void 0 ? _a : 0;
|
|
108
110
|
}
|
|
109
111
|
async dropDatabase() {
|
|
110
112
|
await this.truncateTables();
|
|
@@ -146,6 +148,7 @@ class PostgresDatabase {
|
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
async deleteOne(collection, query) {
|
|
151
|
+
var _a;
|
|
149
152
|
if (!query.id) {
|
|
150
153
|
const match = await this.findOne(collection, query, {
|
|
151
154
|
includeFields: ['id'],
|
|
@@ -157,7 +160,7 @@ class PostgresDatabase {
|
|
|
157
160
|
text: sql,
|
|
158
161
|
values,
|
|
159
162
|
});
|
|
160
|
-
return results.rowCount;
|
|
163
|
+
return (_a = results.rowCount) !== null && _a !== void 0 ? _a : 0;
|
|
161
164
|
}
|
|
162
165
|
async truncateTables() {
|
|
163
166
|
const res = await this.client.query(`
|
|
@@ -205,7 +208,7 @@ class PostgresDatabase {
|
|
|
205
208
|
}
|
|
206
209
|
}
|
|
207
210
|
async connect() {
|
|
208
|
-
var _a;
|
|
211
|
+
var _a, _b, _c;
|
|
209
212
|
this.client = new pg_1.Client({
|
|
210
213
|
connectionString: this.connectionString,
|
|
211
214
|
});
|
|
@@ -214,14 +217,14 @@ class PostgresDatabase {
|
|
|
214
217
|
}
|
|
215
218
|
catch (err) {
|
|
216
219
|
const message = err.message;
|
|
217
|
-
if (message === null ||
|
|
220
|
+
if ((_b = ((_a = err.code) !== null && _a !== void 0 ? _a : message)) === null || _b === void 0 ? void 0 : _b.includes('ECONNREFUSED')) {
|
|
218
221
|
throw new data_stores_1.DataStoresError({
|
|
219
222
|
code: 'UNABLE_TO_CONNECT_TO_DB',
|
|
220
223
|
originalError: err,
|
|
221
224
|
});
|
|
222
225
|
}
|
|
223
226
|
if (message === null || message === void 0 ? void 0 : message.includes('does not exist')) {
|
|
224
|
-
const match = (
|
|
227
|
+
const match = (_c = message.match(/"([^"]*)"/)) !== null && _c !== void 0 ? _c : ['', ''];
|
|
225
228
|
throw new data_stores_1.DataStoresError({
|
|
226
229
|
code: 'INVALID_DATABASE_NAME',
|
|
227
230
|
suppliedName: match[1],
|
|
@@ -28,13 +28,14 @@ export default class PostgresDatabase {
|
|
|
28
28
|
: `${this.idCount++}`;
|
|
29
29
|
}
|
|
30
30
|
update(collection, query, updates) {
|
|
31
|
+
var _a;
|
|
31
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
33
|
const { sql, values } = this.queries.update(collection, query, updates, false);
|
|
33
34
|
const results = yield this.client.query({
|
|
34
35
|
text: sql,
|
|
35
36
|
values,
|
|
36
37
|
});
|
|
37
|
-
return results.rowCount;
|
|
38
|
+
return (_a = results.rowCount) !== null && _a !== void 0 ? _a : 0;
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
count(collection, query) {
|
|
@@ -99,13 +100,14 @@ export default class PostgresDatabase {
|
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
delete(collection, query) {
|
|
103
|
+
var _a;
|
|
102
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
105
|
const { sql, values } = this.queries.delete(collection, query);
|
|
104
106
|
const results = yield this.client.query({
|
|
105
107
|
text: sql,
|
|
106
108
|
values,
|
|
107
109
|
});
|
|
108
|
-
return results.rowCount;
|
|
110
|
+
return (_a = results.rowCount) !== null && _a !== void 0 ? _a : 0;
|
|
109
111
|
});
|
|
110
112
|
}
|
|
111
113
|
dropDatabase() {
|
|
@@ -158,6 +160,7 @@ export default class PostgresDatabase {
|
|
|
158
160
|
});
|
|
159
161
|
}
|
|
160
162
|
deleteOne(collection, query) {
|
|
163
|
+
var _a;
|
|
161
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
165
|
if (!query.id) {
|
|
163
166
|
const match = yield this.findOne(collection, query, {
|
|
@@ -170,7 +173,7 @@ export default class PostgresDatabase {
|
|
|
170
173
|
text: sql,
|
|
171
174
|
values,
|
|
172
175
|
});
|
|
173
|
-
return results.rowCount;
|
|
176
|
+
return (_a = results.rowCount) !== null && _a !== void 0 ? _a : 0;
|
|
174
177
|
});
|
|
175
178
|
}
|
|
176
179
|
truncateTables() {
|
|
@@ -227,7 +230,7 @@ export default class PostgresDatabase {
|
|
|
227
230
|
});
|
|
228
231
|
}
|
|
229
232
|
connect() {
|
|
230
|
-
var _a;
|
|
233
|
+
var _a, _b, _c;
|
|
231
234
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
235
|
this.client = new Client({
|
|
233
236
|
connectionString: this.connectionString,
|
|
@@ -237,14 +240,14 @@ export default class PostgresDatabase {
|
|
|
237
240
|
}
|
|
238
241
|
catch (err) {
|
|
239
242
|
const message = err.message;
|
|
240
|
-
if (message === null ||
|
|
243
|
+
if ((_b = ((_a = err.code) !== null && _a !== void 0 ? _a : message)) === null || _b === void 0 ? void 0 : _b.includes('ECONNREFUSED')) {
|
|
241
244
|
throw new DataStoresError({
|
|
242
245
|
code: 'UNABLE_TO_CONNECT_TO_DB',
|
|
243
246
|
originalError: err,
|
|
244
247
|
});
|
|
245
248
|
}
|
|
246
249
|
if (message === null || message === void 0 ? void 0 : message.includes('does not exist')) {
|
|
247
|
-
const match = (
|
|
250
|
+
const match = (_c = message.match(/"([^"]*)"/)) !== null && _c !== void 0 ? _c : ['', ''];
|
|
248
251
|
throw new DataStoresError({
|
|
249
252
|
code: 'INVALID_DATABASE_NAME',
|
|
250
253
|
suppliedName: match[1],
|
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"sprucebot",
|
|
23
23
|
"sprucelabs"
|
|
24
24
|
],
|
|
25
|
-
"version": "4.1.
|
|
25
|
+
"version": "4.1.16",
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build.ci": "yarn build.tsc && yarn build.resolve-paths && yarn lint",
|
|
28
28
|
"build.dev": "yarn build.tsc --sourceMap ; yarn resolve-paths.lint",
|
|
@@ -51,27 +51,27 @@
|
|
|
51
51
|
"watch.tsc": "tsc -w"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@sprucelabs/data-stores": "^25.
|
|
55
|
-
"@sprucelabs/schema": "^29.0.
|
|
54
|
+
"@sprucelabs/data-stores": "^25.13.2",
|
|
55
|
+
"@sprucelabs/schema": "^29.0.84",
|
|
56
56
|
"pg": "^8.11.3"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@sprucelabs/esm-postbuild": "^5.0.
|
|
60
|
-
"@sprucelabs/jest-json-reporter": "^7.0.
|
|
61
|
-
"@sprucelabs/resolve-path-aliases": "^1.1.
|
|
59
|
+
"@sprucelabs/esm-postbuild": "^5.0.93",
|
|
60
|
+
"@sprucelabs/jest-json-reporter": "^7.0.120",
|
|
61
|
+
"@sprucelabs/resolve-path-aliases": "^1.1.261",
|
|
62
62
|
"@sprucelabs/semantic-release": "^4.0.8",
|
|
63
63
|
"@sprucelabs/spruce-test-fixtures": "^52.8.0",
|
|
64
|
-
"@sprucelabs/test": "^8.0.
|
|
65
|
-
"@sprucelabs/test-utils": "^4.0.
|
|
64
|
+
"@sprucelabs/test": "^8.0.28",
|
|
65
|
+
"@sprucelabs/test-utils": "^4.0.72",
|
|
66
66
|
"@types/node": "^18.14.0",
|
|
67
|
-
"@types/pg": "^8.10.
|
|
67
|
+
"@types/pg": "^8.10.9",
|
|
68
68
|
"chokidar-cli": "^3.0.0",
|
|
69
69
|
"concurrently": "^8.2.2",
|
|
70
70
|
"eslint": "^8.53.0",
|
|
71
71
|
"eslint-config-spruce": "^10.13.6",
|
|
72
72
|
"jest": "^29.7.0",
|
|
73
73
|
"jest-circus": "^29.7.0",
|
|
74
|
-
"prettier": "^3.0
|
|
74
|
+
"prettier": "^3.1.0",
|
|
75
75
|
"ts-node": "^10.9.1",
|
|
76
76
|
"tsc-watch": "^6.0.4",
|
|
77
77
|
"typescript": "^5.2.2"
|