@nymphjs/driver-postgresql 1.0.0-beta.40 → 1.0.0-beta.42
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/CHANGELOG.md +10 -0
- package/dist/PostgreSQLDriver.d.ts +1 -17
- package/dist/PostgreSQLDriver.js +43 -145
- package/dist/PostgreSQLDriver.js.map +1 -1
- package/package.json +6 -6
- package/src/PostgreSQLDriver.ts +43 -242
- package/dist/runPostgresqlSync.js +0 -41
- package/src/runPostgresqlSync.js +0 -41
- package/src/testpostgresql.js +0 -119
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-beta.42](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.41...v1.0.0-beta.42) (2023-07-12)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
9
|
+
|
|
10
|
+
# [1.0.0-beta.41](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.40...v1.0.0-beta.41) (2023-07-12)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- remove synchronous database queries ([b579fb2](https://github.com/sciactive/nymphjs/commit/b579fb2eacd96cdd1b386a62c5c00cdbb2438f6e))
|
|
15
|
+
|
|
6
16
|
# [1.0.0-beta.40](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.39...v1.0.0-beta.40) (2023-07-10)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Worker } from 'node:worker_threads';
|
|
3
1
|
import { Pool, PoolClient } from 'pg';
|
|
4
2
|
import { NymphDriver, EntityConstructor, EntityInterface, FormattedSelector, Options, Selector } from '@nymphjs/nymph';
|
|
5
3
|
import { PostgreSQLDriverConfig } from './conf';
|
|
@@ -18,10 +16,9 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
18
16
|
protected connected: boolean;
|
|
19
17
|
protected link: Pool;
|
|
20
18
|
protected transaction: PostgreSQLDriverTransaction | null;
|
|
21
|
-
protected worker: Worker;
|
|
22
19
|
static escape(input: string): string;
|
|
23
20
|
static escapeValue(input: string): string;
|
|
24
|
-
constructor(config: Partial<PostgreSQLDriverConfig>, link?: Pool, transaction?: PostgreSQLDriverTransaction
|
|
21
|
+
constructor(config: Partial<PostgreSQLDriverConfig>, link?: Pool, transaction?: PostgreSQLDriverTransaction);
|
|
25
22
|
clone(): PostgreSQLDriver;
|
|
26
23
|
private getConnection;
|
|
27
24
|
connect(): Promise<true>;
|
|
@@ -31,12 +28,9 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
31
28
|
private createTables;
|
|
32
29
|
private translateQuery;
|
|
33
30
|
private query;
|
|
34
|
-
private querySync;
|
|
35
31
|
private queryIter;
|
|
36
|
-
private queryIterSync;
|
|
37
32
|
private queryGet;
|
|
38
33
|
private queryRun;
|
|
39
|
-
private queryRunSync;
|
|
40
34
|
commit(name: string): Promise<boolean>;
|
|
41
35
|
deleteEntityByID(guid: string, className?: EntityConstructor | string | null): Promise<boolean>;
|
|
42
36
|
deleteUID(name: string): Promise<boolean>;
|
|
@@ -45,9 +39,6 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
45
39
|
protected performQuery(options: Options, formattedSelectors: FormattedSelector[], etype: string): {
|
|
46
40
|
result: any;
|
|
47
41
|
};
|
|
48
|
-
protected performQuerySync(options: Options, formattedSelectors: FormattedSelector[], etype: string): {
|
|
49
|
-
result: any;
|
|
50
|
-
};
|
|
51
42
|
getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
52
43
|
return: 'count';
|
|
53
44
|
}, ...selectors: Selector[]): Promise<number>;
|
|
@@ -55,13 +46,6 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
55
46
|
return: 'guid';
|
|
56
47
|
}, ...selectors: Selector[]): Promise<string[]>;
|
|
57
48
|
getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<ReturnType<T['factorySync']>[]>;
|
|
58
|
-
protected getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
59
|
-
return: 'count';
|
|
60
|
-
}, ...selectors: Selector[]): number;
|
|
61
|
-
protected getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
62
|
-
return: 'guid';
|
|
63
|
-
}, ...selectors: Selector[]): string[];
|
|
64
|
-
protected getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): ReturnType<T['factorySync']>[];
|
|
65
49
|
getUID(name: string): Promise<number | null>;
|
|
66
50
|
import(filename: string): Promise<boolean>;
|
|
67
51
|
newUID(name: string): Promise<number>;
|
package/dist/PostgreSQLDriver.js
CHANGED
|
@@ -3,8 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_worker_threads_1 = require("node:worker_threads");
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
6
|
const pg_1 = require("pg");
|
|
9
7
|
const pg_format_1 = __importDefault(require("pg-format"));
|
|
10
8
|
const nymph_1 = require("@nymphjs/nymph");
|
|
@@ -17,7 +15,7 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
17
15
|
static escapeValue(input) {
|
|
18
16
|
return pg_format_1.default.literal(input);
|
|
19
17
|
}
|
|
20
|
-
constructor(config, link, transaction
|
|
18
|
+
constructor(config, link, transaction) {
|
|
21
19
|
super();
|
|
22
20
|
this.connected = false;
|
|
23
21
|
this.transaction = null;
|
|
@@ -38,15 +36,12 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
38
36
|
if (transaction != null) {
|
|
39
37
|
this.transaction = transaction;
|
|
40
38
|
}
|
|
41
|
-
if (worker != null) {
|
|
42
|
-
this.worker = worker;
|
|
43
|
-
}
|
|
44
39
|
if (link == null) {
|
|
45
40
|
this.connect();
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
43
|
clone() {
|
|
49
|
-
return new PostgreSQLDriver(this.config, this.link, this.transaction ?? undefined
|
|
44
|
+
return new PostgreSQLDriver(this.config, this.link, this.transaction ?? undefined);
|
|
50
45
|
}
|
|
51
46
|
getConnection() {
|
|
52
47
|
if (this.transaction != null && this.transaction.connection != null) {
|
|
@@ -65,7 +60,6 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
65
60
|
resolve(0);
|
|
66
61
|
}));
|
|
67
62
|
connection.done();
|
|
68
|
-
this.worker.postMessage('halt');
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
catch (e) {
|
|
@@ -74,18 +68,6 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
74
68
|
if (!this.connected) {
|
|
75
69
|
try {
|
|
76
70
|
this.link = new pg_1.Pool(this.postgresqlConfig);
|
|
77
|
-
const worker = new node_worker_threads_1.Worker((0, node_path_1.resolve)(__dirname, 'runPostgresqlSync.js'), {
|
|
78
|
-
workerData: this.postgresqlConfig,
|
|
79
|
-
});
|
|
80
|
-
worker.on('message', (message) => {
|
|
81
|
-
if (message === 'halted') {
|
|
82
|
-
worker.terminate();
|
|
83
|
-
}
|
|
84
|
-
else if (typeof message === 'object' && 'error' in message) {
|
|
85
|
-
console.error('Worker Thread Error', message.error);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
this.worker = worker;
|
|
89
71
|
this.connected = true;
|
|
90
72
|
}
|
|
91
73
|
catch (e) {
|
|
@@ -105,7 +87,6 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
105
87
|
async disconnect() {
|
|
106
88
|
if (this.connected) {
|
|
107
89
|
await new Promise((resolve) => this.link.end(() => resolve(0)));
|
|
108
|
-
this.worker.postMessage('halt');
|
|
109
90
|
this.connected = false;
|
|
110
91
|
}
|
|
111
92
|
return this.connected;
|
|
@@ -116,23 +97,23 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
116
97
|
isConnected() {
|
|
117
98
|
return this.connected;
|
|
118
99
|
}
|
|
119
|
-
createTables(etype = null) {
|
|
100
|
+
async createTables(etype = null) {
|
|
120
101
|
if (etype != null) {
|
|
121
|
-
this.
|
|
102
|
+
await this.queryRun(`CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} (
|
|
122
103
|
"guid" BYTEA NOT NULL,
|
|
123
104
|
"tags" TEXT[],
|
|
124
105
|
"cdate" DOUBLE PRECISION NOT NULL,
|
|
125
106
|
"mdate" DOUBLE PRECISION NOT NULL,
|
|
126
107
|
PRIMARY KEY ("guid")
|
|
127
108
|
) WITH ( OIDS=FALSE );`);
|
|
128
|
-
this.
|
|
129
|
-
this.
|
|
130
|
-
this.
|
|
131
|
-
this.
|
|
132
|
-
this.
|
|
133
|
-
this.
|
|
134
|
-
this.
|
|
135
|
-
this.
|
|
109
|
+
await this.queryRun(`ALTER TABLE ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`);
|
|
110
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_cdate`)};`);
|
|
111
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_cdate`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING btree ("cdate");`);
|
|
112
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_mdate`)};`);
|
|
113
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_mdate`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING btree ("mdate");`);
|
|
114
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_tags`)};`);
|
|
115
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_tags`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING gin ("tags");`);
|
|
116
|
+
await this.queryRun(`CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} (
|
|
136
117
|
"guid" BYTEA NOT NULL,
|
|
137
118
|
"name" TEXT NOT NULL,
|
|
138
119
|
"value" TEXT NOT NULL,
|
|
@@ -140,16 +121,16 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
140
121
|
FOREIGN KEY ("guid")
|
|
141
122
|
REFERENCES ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ("guid") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE
|
|
142
123
|
) WITH ( OIDS=FALSE );`);
|
|
143
|
-
this.
|
|
144
|
-
this.
|
|
145
|
-
this.
|
|
146
|
-
this.
|
|
147
|
-
this.
|
|
148
|
-
this.
|
|
149
|
-
this.
|
|
150
|
-
this.
|
|
151
|
-
this.
|
|
152
|
-
this.
|
|
124
|
+
await this.queryRun(`ALTER TABLE ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`);
|
|
125
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}_id_guid`)};`);
|
|
126
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}_id_guid`)} ON ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} USING btree ("guid");`);
|
|
127
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}_id_name`)};`);
|
|
128
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}_id_name`)} ON ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} USING btree ("name");`);
|
|
129
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}_id_guid_name__user`)};`);
|
|
130
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}_id_guid_name__user`)} ON ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} USING btree ("guid") WHERE "name" = 'user'::text;`);
|
|
131
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}_id_guid_name__group`)};`);
|
|
132
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}_id_guid_name__group`)} ON ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} USING btree ("guid") WHERE "name" = 'group'::text;`);
|
|
133
|
+
await this.queryRun(`CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}`)} (
|
|
153
134
|
"guid" BYTEA NOT NULL,
|
|
154
135
|
"name" TEXT NOT NULL,
|
|
155
136
|
"truthy" BOOLEAN,
|
|
@@ -159,16 +140,16 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
159
140
|
FOREIGN KEY ("guid")
|
|
160
141
|
REFERENCES ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ("guid") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE
|
|
161
142
|
) WITH ( OIDS=FALSE );`);
|
|
162
|
-
this.
|
|
163
|
-
this.
|
|
164
|
-
this.
|
|
165
|
-
this.
|
|
166
|
-
this.
|
|
167
|
-
this.
|
|
168
|
-
this.
|
|
169
|
-
this.
|
|
170
|
-
this.
|
|
171
|
-
this.
|
|
143
|
+
await this.queryRun(`ALTER TABLE ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}`)} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`);
|
|
144
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}_id_guid`)};`);
|
|
145
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}_id_guid`)} ON ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}`)} USING btree ("guid");`);
|
|
146
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}_id_name`)};`);
|
|
147
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}_id_name`)} ON ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}`)} USING btree ("name");`);
|
|
148
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}_id_guid_name_truthy`)};`);
|
|
149
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}_id_guid_name_truthy`)} ON ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}`)} USING btree ("guid", "name") WHERE "truthy" = TRUE;`);
|
|
150
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}_id_guid_name_falsy`)};`);
|
|
151
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}_id_guid_name_falsy`)} ON ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}`)} USING btree ("guid", "name") WHERE "truthy" <> TRUE;`);
|
|
152
|
+
await this.queryRun(`CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}`)} (
|
|
172
153
|
"guid" BYTEA NOT NULL,
|
|
173
154
|
"name" TEXT NOT NULL,
|
|
174
155
|
"reference" BYTEA NOT NULL,
|
|
@@ -176,21 +157,21 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
176
157
|
FOREIGN KEY ("guid")
|
|
177
158
|
REFERENCES ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ("guid") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE
|
|
178
159
|
) WITH ( OIDS=FALSE );`);
|
|
179
|
-
this.
|
|
180
|
-
this.
|
|
181
|
-
this.
|
|
182
|
-
this.
|
|
183
|
-
this.
|
|
184
|
-
this.
|
|
185
|
-
this.
|
|
160
|
+
await this.queryRun(`ALTER TABLE ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}`)} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`);
|
|
161
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}_id_guid`)};`);
|
|
162
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}_id_guid`)} ON ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}`)} USING btree ("guid");`);
|
|
163
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}_id_name`)};`);
|
|
164
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}_id_name`)} ON ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}`)} USING btree ("name");`);
|
|
165
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}_id_reference`)};`);
|
|
166
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}_id_reference`)} ON ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}`)} USING btree ("reference");`);
|
|
186
167
|
}
|
|
187
168
|
else {
|
|
188
|
-
this.
|
|
169
|
+
await this.queryRun(`CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(`${this.prefix}uids`)} (
|
|
189
170
|
"name" TEXT NOT NULL,
|
|
190
171
|
"cur_uid" BIGINT NOT NULL,
|
|
191
172
|
PRIMARY KEY ("name")
|
|
192
173
|
) WITH ( OIDS = FALSE );`);
|
|
193
|
-
this.
|
|
174
|
+
await this.queryRun(`ALTER TABLE ${PostgreSQLDriver.escape(`${this.prefix}uids`)} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`);
|
|
194
175
|
}
|
|
195
176
|
return true;
|
|
196
177
|
}
|
|
@@ -213,9 +194,9 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
213
194
|
}
|
|
214
195
|
catch (e) {
|
|
215
196
|
const errorCode = e?.code;
|
|
216
|
-
if (errorCode === '42P01' && this.createTables()) {
|
|
197
|
+
if (errorCode === '42P01' && (await this.createTables())) {
|
|
217
198
|
for (let etype of etypes) {
|
|
218
|
-
this.createTables(etype);
|
|
199
|
+
await this.createTables(etype);
|
|
219
200
|
}
|
|
220
201
|
try {
|
|
221
202
|
return await runQuery();
|
|
@@ -229,28 +210,6 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
229
210
|
}
|
|
230
211
|
}
|
|
231
212
|
}
|
|
232
|
-
querySync(runQuery, query, etypes = []) {
|
|
233
|
-
try {
|
|
234
|
-
return runQuery();
|
|
235
|
-
}
|
|
236
|
-
catch (e) {
|
|
237
|
-
const errorCode = e?.code;
|
|
238
|
-
if (errorCode === '42P01' && this.createTables()) {
|
|
239
|
-
for (let etype of etypes) {
|
|
240
|
-
this.createTables(etype);
|
|
241
|
-
}
|
|
242
|
-
try {
|
|
243
|
-
return runQuery();
|
|
244
|
-
}
|
|
245
|
-
catch (e2) {
|
|
246
|
-
throw new nymph_1.QueryFailedError('Query failed: ' + e2?.code + ' - ' + e2?.message, query);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
throw e;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
213
|
queryIter(query, { etypes = [], params = {}, } = {}) {
|
|
255
214
|
const { query: newQuery, params: newParams } = this.translateQuery(query, params);
|
|
256
215
|
return this.query(async () => {
|
|
@@ -267,22 +226,6 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
267
226
|
return results.rows;
|
|
268
227
|
}, `${query} -- ${JSON.stringify(params)}`, etypes);
|
|
269
228
|
}
|
|
270
|
-
queryIterSync(query, { etypes = [], params = {}, } = {}) {
|
|
271
|
-
const { query: newQuery, params: newParams } = this.translateQuery(query, params);
|
|
272
|
-
return this.querySync(() => {
|
|
273
|
-
const channel = new node_worker_threads_1.MessageChannel();
|
|
274
|
-
this.worker.postMessage({ query: newQuery, params: newParams, port: channel.port2 }, [channel.port2]);
|
|
275
|
-
let output = undefined;
|
|
276
|
-
while (!output) {
|
|
277
|
-
output = (0, node_worker_threads_1.receiveMessageOnPort)(channel.port1);
|
|
278
|
-
}
|
|
279
|
-
if (output.message.error) {
|
|
280
|
-
throw new Error(output.message.error);
|
|
281
|
-
}
|
|
282
|
-
const { results } = output.message;
|
|
283
|
-
return results.rows;
|
|
284
|
-
}, `${query} -- ${JSON.stringify(params)}`, etypes);
|
|
285
|
-
}
|
|
286
229
|
queryGet(query, { etypes = [], params = {}, } = {}) {
|
|
287
230
|
const { query: newQuery, params: newParams } = this.translateQuery(query, params);
|
|
288
231
|
return this.query(async () => {
|
|
@@ -315,22 +258,6 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
315
258
|
return { rowCount: results.rowCount ?? 0 };
|
|
316
259
|
}, `${query} -- ${JSON.stringify(params)}`, etypes);
|
|
317
260
|
}
|
|
318
|
-
queryRunSync(query, { etypes = [], params = {}, } = {}) {
|
|
319
|
-
const { query: newQuery, params: newParams } = this.translateQuery(query, params);
|
|
320
|
-
return this.querySync(() => {
|
|
321
|
-
const channel = new node_worker_threads_1.MessageChannel();
|
|
322
|
-
this.worker.postMessage({ query: newQuery, params: newParams, port: channel.port2 }, [channel.port2]);
|
|
323
|
-
let output = undefined;
|
|
324
|
-
while (!output) {
|
|
325
|
-
output = (0, node_worker_threads_1.receiveMessageOnPort)(channel.port1);
|
|
326
|
-
}
|
|
327
|
-
if (output.message.error) {
|
|
328
|
-
throw new Error(output.message.error);
|
|
329
|
-
}
|
|
330
|
-
const { results } = output.message;
|
|
331
|
-
return { rowCount: results.rowCount ?? 0 };
|
|
332
|
-
}, `${query} -- ${JSON.stringify(params)}`, etypes);
|
|
333
|
-
}
|
|
334
261
|
async commit(name) {
|
|
335
262
|
if (name == null || typeof name !== 'string' || name.length === 0) {
|
|
336
263
|
throw new nymph_1.InvalidParametersError('Transaction commit attempted without a name.');
|
|
@@ -1438,13 +1365,6 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1438
1365
|
result,
|
|
1439
1366
|
};
|
|
1440
1367
|
}
|
|
1441
|
-
performQuerySync(options, formattedSelectors, etype) {
|
|
1442
|
-
const { query, params, etypes } = this.makeEntityQuery(options, formattedSelectors, etype);
|
|
1443
|
-
const result = (this.queryIterSync(query, { etypes, params }) || [])[Symbol.iterator]();
|
|
1444
|
-
return {
|
|
1445
|
-
result,
|
|
1446
|
-
};
|
|
1447
|
-
}
|
|
1448
1368
|
async getEntities(options = {}, ...selectors) {
|
|
1449
1369
|
const { result: resultPromise, process } = this.getEntitesRowLike(options, selectors, (options, formattedSelectors, etype) => this.performQuery(options, formattedSelectors, etype), () => {
|
|
1450
1370
|
const next = result.next();
|
|
@@ -1468,28 +1388,6 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1468
1388
|
}
|
|
1469
1389
|
return value;
|
|
1470
1390
|
}
|
|
1471
|
-
getEntitiesSync(options = {}, ...selectors) {
|
|
1472
|
-
const { result, process } = this.getEntitesRowLike(options, selectors, (options, formattedSelectors, etype) => this.performQuerySync(options, formattedSelectors, etype), () => {
|
|
1473
|
-
const next = result.next();
|
|
1474
|
-
return next.done ? null : next.value;
|
|
1475
|
-
}, () => undefined, (row) => Number(row.count), (row) => row.guid, (row) => ({
|
|
1476
|
-
tags: row.tags,
|
|
1477
|
-
cdate: isNaN(Number(row.cdate)) ? null : Number(row.cdate),
|
|
1478
|
-
mdate: isNaN(Number(row.mdate)) ? null : Number(row.mdate),
|
|
1479
|
-
}), (row) => ({
|
|
1480
|
-
name: row.name,
|
|
1481
|
-
svalue: row.value === 'N'
|
|
1482
|
-
? JSON.stringify(Number(row.number))
|
|
1483
|
-
: row.value === 'S'
|
|
1484
|
-
? JSON.stringify(row.string)
|
|
1485
|
-
: row.value,
|
|
1486
|
-
}));
|
|
1487
|
-
const value = process();
|
|
1488
|
-
if (value instanceof Error) {
|
|
1489
|
-
throw value;
|
|
1490
|
-
}
|
|
1491
|
-
return value;
|
|
1492
|
-
}
|
|
1493
1391
|
async getUID(name) {
|
|
1494
1392
|
if (name == null) {
|
|
1495
1393
|
throw new nymph_1.InvalidParametersError('Name not given for UID.');
|