@nymphjs/driver-postgresql 1.0.0-beta.4 → 1.0.0-beta.40
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 +152 -0
- package/dist/PostgreSQLDriver.d.ts +5 -1
- package/dist/PostgreSQLDriver.js +90 -61
- package/dist/PostgreSQLDriver.js.map +1 -1
- package/dist/runPostgresqlSync.js +34 -28
- package/package.json +14 -16
- package/src/PostgreSQLDriver.ts +127 -67
- package/src/runPostgresqlSync.js +34 -28
- package/src/testpostgresql.js +78 -18
- package/typedoc.json +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,158 @@
|
|
|
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.40](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.39...v1.0.0-beta.40) (2023-07-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
9
|
+
|
|
10
|
+
# [1.0.0-beta.39](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.38...v1.0.0-beta.39) (2023-07-09)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
13
|
+
|
|
14
|
+
# [1.0.0-beta.38](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.37...v1.0.0-beta.38) (2023-07-09)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
17
|
+
|
|
18
|
+
# [1.0.0-beta.37](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.36...v1.0.0-beta.37) (2023-07-09)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
21
|
+
|
|
22
|
+
# [1.0.0-beta.36](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.35...v1.0.0-beta.36) (2023-07-09)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
25
|
+
|
|
26
|
+
# [1.0.0-beta.35](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.34...v1.0.0-beta.35) (2023-06-14)
|
|
27
|
+
|
|
28
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
29
|
+
|
|
30
|
+
# [1.0.0-beta.34](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.33...v1.0.0-beta.34) (2023-05-13)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
33
|
+
|
|
34
|
+
# [1.0.0-beta.33](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.32...v1.0.0-beta.33) (2023-05-13)
|
|
35
|
+
|
|
36
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
37
|
+
|
|
38
|
+
# [1.0.0-beta.32](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.31...v1.0.0-beta.32) (2023-05-13)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
41
|
+
|
|
42
|
+
# [1.0.0-beta.31](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.30...v1.0.0-beta.31) (2023-05-12)
|
|
43
|
+
|
|
44
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
45
|
+
|
|
46
|
+
# [1.0.0-beta.30](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.29...v1.0.0-beta.30) (2023-05-12)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
49
|
+
|
|
50
|
+
# [1.0.0-beta.29](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.28...v1.0.0-beta.29) (2023-05-08)
|
|
51
|
+
|
|
52
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
53
|
+
|
|
54
|
+
# [1.0.0-beta.28](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.27...v1.0.0-beta.28) (2023-05-05)
|
|
55
|
+
|
|
56
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
57
|
+
|
|
58
|
+
# [1.0.0-beta.27](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.26...v1.0.0-beta.27) (2023-05-04)
|
|
59
|
+
|
|
60
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
61
|
+
|
|
62
|
+
# [1.0.0-beta.26](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.25...v1.0.0-beta.26) (2023-05-04)
|
|
63
|
+
|
|
64
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
65
|
+
|
|
66
|
+
# [1.0.0-beta.25](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.24...v1.0.0-beta.25) (2023-05-04)
|
|
67
|
+
|
|
68
|
+
### Bug Fixes
|
|
69
|
+
|
|
70
|
+
- don't create empty entities ([1d4d2e9](https://github.com/sciactive/nymphjs/commit/1d4d2e99af2e9cdc647bcf58ac34572836f41176))
|
|
71
|
+
|
|
72
|
+
# [1.0.0-beta.24](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.23...v1.0.0-beta.24) (2023-05-02)
|
|
73
|
+
|
|
74
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
75
|
+
|
|
76
|
+
# [1.0.0-beta.23](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.22...v1.0.0-beta.23) (2023-05-02)
|
|
77
|
+
|
|
78
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
79
|
+
|
|
80
|
+
# [1.0.0-beta.22](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.21...v1.0.0-beta.22) (2023-05-01)
|
|
81
|
+
|
|
82
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
83
|
+
|
|
84
|
+
# [1.0.0-beta.21](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.20...v1.0.0-beta.21) (2023-05-01)
|
|
85
|
+
|
|
86
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
87
|
+
|
|
88
|
+
# [1.0.0-beta.20](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.19...v1.0.0-beta.20) (2023-04-30)
|
|
89
|
+
|
|
90
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
91
|
+
|
|
92
|
+
# [1.0.0-beta.19](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.18...v1.0.0-beta.19) (2023-04-29)
|
|
93
|
+
|
|
94
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
95
|
+
|
|
96
|
+
# [1.0.0-beta.18](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.17...v1.0.0-beta.18) (2023-04-27)
|
|
97
|
+
|
|
98
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
99
|
+
|
|
100
|
+
# [1.0.0-beta.17](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.16...v1.0.0-beta.17) (2023-04-24)
|
|
101
|
+
|
|
102
|
+
### Features
|
|
103
|
+
|
|
104
|
+
- use a long lived worker thread for synchronous mysql and postgres queries ([7e2bf84](https://github.com/sciactive/nymphjs/commit/7e2bf84a2d584d6906c31f44147025b793a05026))
|
|
105
|
+
|
|
106
|
+
# [1.0.0-beta.16](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.15...v1.0.0-beta.16) (2023-03-31)
|
|
107
|
+
|
|
108
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
109
|
+
|
|
110
|
+
# [1.0.0-beta.15](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.14...v1.0.0-beta.15) (2023-03-23)
|
|
111
|
+
|
|
112
|
+
### Features
|
|
113
|
+
|
|
114
|
+
- add option to sort results by a property ([16384e7](https://github.com/sciactive/nymphjs/commit/16384e7bdab88abb55ccccabb06ac09f92fa8a03))
|
|
115
|
+
|
|
116
|
+
# [1.0.0-beta.14](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.13...v1.0.0-beta.14) (2023-03-17)
|
|
117
|
+
|
|
118
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
119
|
+
|
|
120
|
+
# [1.0.0-beta.13](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.12...v1.0.0-beta.13) (2023-03-16)
|
|
121
|
+
|
|
122
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
123
|
+
|
|
124
|
+
# [1.0.0-beta.12](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.11...v1.0.0-beta.12) (2023-03-04)
|
|
125
|
+
|
|
126
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
127
|
+
|
|
128
|
+
# [1.0.0-beta.11](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.10...v1.0.0-beta.11) (2023-02-27)
|
|
129
|
+
|
|
130
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
131
|
+
|
|
132
|
+
# [1.0.0-beta.10](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2023-01-19)
|
|
133
|
+
|
|
134
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
135
|
+
|
|
136
|
+
# [1.0.0-beta.9](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.8...v1.0.0-beta.9) (2023-01-09)
|
|
137
|
+
|
|
138
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
139
|
+
|
|
140
|
+
# [1.0.0-beta.8](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.7...v1.0.0-beta.8) (2023-01-09)
|
|
141
|
+
|
|
142
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
143
|
+
|
|
144
|
+
# [1.0.0-beta.7](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.6...v1.0.0-beta.7) (2023-01-05)
|
|
145
|
+
|
|
146
|
+
### Bug Fixes
|
|
147
|
+
|
|
148
|
+
- sqlite transaction returns wrong instance of nymph if it has been cloned ([b278c76](https://github.com/sciactive/nymphjs/commit/b278c7633722cb1cca7a941187ae2f1ff8ebdc7b))
|
|
149
|
+
|
|
150
|
+
# [1.0.0-beta.6](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.5...v1.0.0-beta.6) (2023-01-05)
|
|
151
|
+
|
|
152
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
153
|
+
|
|
154
|
+
# [1.0.0-beta.5](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.4...v1.0.0-beta.5) (2022-11-24)
|
|
155
|
+
|
|
156
|
+
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
157
|
+
|
|
6
158
|
# [1.0.0-beta.4](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.3...v1.0.0-beta.4) (2022-11-23)
|
|
7
159
|
|
|
8
160
|
**Note:** Version bump only for package @nymphjs/driver-postgresql
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Worker } from 'node:worker_threads';
|
|
1
3
|
import { Pool, PoolClient } from 'pg';
|
|
2
4
|
import { NymphDriver, EntityConstructor, EntityInterface, FormattedSelector, Options, Selector } from '@nymphjs/nymph';
|
|
3
5
|
import { PostgreSQLDriverConfig } from './conf';
|
|
@@ -16,9 +18,11 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
16
18
|
protected connected: boolean;
|
|
17
19
|
protected link: Pool;
|
|
18
20
|
protected transaction: PostgreSQLDriverTransaction | null;
|
|
21
|
+
protected worker: Worker;
|
|
19
22
|
static escape(input: string): string;
|
|
20
23
|
static escapeValue(input: string): string;
|
|
21
|
-
constructor(config: Partial<PostgreSQLDriverConfig>, link?: Pool, transaction?: PostgreSQLDriverTransaction);
|
|
24
|
+
constructor(config: Partial<PostgreSQLDriverConfig>, link?: Pool, transaction?: PostgreSQLDriverTransaction, worker?: Worker);
|
|
25
|
+
clone(): PostgreSQLDriver;
|
|
22
26
|
private getConnection;
|
|
23
27
|
connect(): Promise<true>;
|
|
24
28
|
disconnect(): Promise<false>;
|
package/dist/PostgreSQLDriver.js
CHANGED
|
@@ -3,7 +3,8 @@ 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
|
|
6
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
7
8
|
const pg_1 = require("pg");
|
|
8
9
|
const pg_format_1 = __importDefault(require("pg-format"));
|
|
9
10
|
const nymph_1 = require("@nymphjs/nymph");
|
|
@@ -16,7 +17,7 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
16
17
|
static escapeValue(input) {
|
|
17
18
|
return pg_format_1.default.literal(input);
|
|
18
19
|
}
|
|
19
|
-
constructor(config, link, transaction) {
|
|
20
|
+
constructor(config, link, transaction, worker) {
|
|
20
21
|
super();
|
|
21
22
|
this.connected = false;
|
|
22
23
|
this.transaction = null;
|
|
@@ -37,10 +38,16 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
37
38
|
if (transaction != null) {
|
|
38
39
|
this.transaction = transaction;
|
|
39
40
|
}
|
|
41
|
+
if (worker != null) {
|
|
42
|
+
this.worker = worker;
|
|
43
|
+
}
|
|
40
44
|
if (link == null) {
|
|
41
45
|
this.connect();
|
|
42
46
|
}
|
|
43
47
|
}
|
|
48
|
+
clone() {
|
|
49
|
+
return new PostgreSQLDriver(this.config, this.link, this.transaction ?? undefined, this.worker ?? undefined);
|
|
50
|
+
}
|
|
44
51
|
getConnection() {
|
|
45
52
|
if (this.transaction != null && this.transaction.connection != null) {
|
|
46
53
|
return Promise.resolve(this.transaction.connection);
|
|
@@ -58,6 +65,7 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
58
65
|
resolve(0);
|
|
59
66
|
}));
|
|
60
67
|
connection.done();
|
|
68
|
+
this.worker.postMessage('halt');
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
catch (e) {
|
|
@@ -66,6 +74,18 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
66
74
|
if (!this.connected) {
|
|
67
75
|
try {
|
|
68
76
|
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;
|
|
69
89
|
this.connected = true;
|
|
70
90
|
}
|
|
71
91
|
catch (e) {
|
|
@@ -85,6 +105,7 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
85
105
|
async disconnect() {
|
|
86
106
|
if (this.connected) {
|
|
87
107
|
await new Promise((resolve) => this.link.end(() => resolve(0)));
|
|
108
|
+
this.worker.postMessage('halt');
|
|
88
109
|
this.connected = false;
|
|
89
110
|
}
|
|
90
111
|
return this.connected;
|
|
@@ -249,30 +270,17 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
249
270
|
queryIterSync(query, { etypes = [], params = {}, } = {}) {
|
|
250
271
|
const { query: newQuery, params: newParams } = this.translateQuery(query, params);
|
|
251
272
|
return this.querySync(() => {
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}),
|
|
258
|
-
timeout: 30000,
|
|
259
|
-
maxBuffer: 100 * 1024 * 1024,
|
|
260
|
-
encoding: 'utf8',
|
|
261
|
-
windowsHide: true,
|
|
262
|
-
});
|
|
263
|
-
try {
|
|
264
|
-
return JSON.parse(output.stdout).rows;
|
|
265
|
-
}
|
|
266
|
-
catch (e) {
|
|
267
|
-
}
|
|
268
|
-
if (output.status === 0) {
|
|
269
|
-
throw new Error('Unknown parse error.');
|
|
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);
|
|
270
278
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
for (const name in err) {
|
|
274
|
-
e[name] = err[name];
|
|
279
|
+
if (output.message.error) {
|
|
280
|
+
throw new Error(output.message.error);
|
|
275
281
|
}
|
|
282
|
+
const { results } = output.message;
|
|
283
|
+
return results.rows;
|
|
276
284
|
}, `${query} -- ${JSON.stringify(params)}`, etypes);
|
|
277
285
|
}
|
|
278
286
|
queryGet(query, { etypes = [], params = {}, } = {}) {
|
|
@@ -310,31 +318,17 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
310
318
|
queryRunSync(query, { etypes = [], params = {}, } = {}) {
|
|
311
319
|
const { query: newQuery, params: newParams } = this.translateQuery(query, params);
|
|
312
320
|
return this.querySync(() => {
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}),
|
|
319
|
-
timeout: 30000,
|
|
320
|
-
maxBuffer: 100 * 1024 * 1024,
|
|
321
|
-
encoding: 'utf8',
|
|
322
|
-
windowsHide: true,
|
|
323
|
-
});
|
|
324
|
-
try {
|
|
325
|
-
const results = JSON.parse(output.stdout);
|
|
326
|
-
return { rowCount: results.rowCount ?? 0 };
|
|
327
|
-
}
|
|
328
|
-
catch (e) {
|
|
329
|
-
}
|
|
330
|
-
if (output.status === 0) {
|
|
331
|
-
throw new Error('Unknown parse error.');
|
|
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);
|
|
332
326
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
for (const name in err) {
|
|
336
|
-
e[name] = err[name];
|
|
327
|
+
if (output.message.error) {
|
|
328
|
+
throw new Error(output.message.error);
|
|
337
329
|
}
|
|
330
|
+
const { results } = output.message;
|
|
331
|
+
return { rowCount: results.rowCount ?? 0 };
|
|
338
332
|
}, `${query} -- ${JSON.stringify(params)}`, etypes);
|
|
339
333
|
}
|
|
340
334
|
async commit(name) {
|
|
@@ -484,6 +478,7 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
484
478
|
const fTable = `f${tableSuffix}`;
|
|
485
479
|
const ieTable = `ie${tableSuffix}`;
|
|
486
480
|
const countTable = `count${tableSuffix}`;
|
|
481
|
+
const sTable = `s${tableSuffix}`;
|
|
487
482
|
const sort = options.sort ?? 'cdate';
|
|
488
483
|
const queryParts = this.iterateSelectorsForQuery(formattedSelectors, (key, value, typeIsOr, typeIsNot) => {
|
|
489
484
|
const clauseNot = key.startsWith('!');
|
|
@@ -1255,18 +1250,38 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1255
1250
|
return curQuery;
|
|
1256
1251
|
});
|
|
1257
1252
|
let sortBy;
|
|
1253
|
+
let sortByInner;
|
|
1254
|
+
let sortJoin = '';
|
|
1255
|
+
let sortJoinInner = '';
|
|
1256
|
+
const order = options.reverse ? ' DESC' : '';
|
|
1258
1257
|
switch (sort) {
|
|
1259
1258
|
case 'mdate':
|
|
1260
|
-
sortBy =
|
|
1259
|
+
sortBy = `${eTable}."mdate"${order}`;
|
|
1260
|
+
sortByInner = `${ieTable}."mdate"${order}`;
|
|
1261
1261
|
break;
|
|
1262
1262
|
case 'cdate':
|
|
1263
|
+
sortBy = `${eTable}."cdate"${order}`;
|
|
1264
|
+
sortByInner = `${ieTable}."cdate"${order}`;
|
|
1265
|
+
break;
|
|
1263
1266
|
default:
|
|
1264
|
-
|
|
1267
|
+
const name = `param${++count.i}`;
|
|
1268
|
+
sortJoin = `LEFT JOIN (
|
|
1269
|
+
SELECT "guid", "string", "number"
|
|
1270
|
+
FROM ${PostgreSQLDriver.escape(this.prefix + 'comparisons_' + etype)}
|
|
1271
|
+
WHERE "name"=@${name}
|
|
1272
|
+
ORDER BY "number"${order}, "string"${order}
|
|
1273
|
+
) ${sTable} ON ${eTable}."guid"=${sTable}."guid"`;
|
|
1274
|
+
sortJoinInner = `LEFT JOIN (
|
|
1275
|
+
SELECT "guid", "string", "number"
|
|
1276
|
+
FROM ${PostgreSQLDriver.escape(this.prefix + 'comparisons_' + etype)}
|
|
1277
|
+
WHERE "name"=@${name}
|
|
1278
|
+
ORDER BY "number"${order}, "string"${order}
|
|
1279
|
+
) ${sTable} ON ${ieTable}."guid"=${sTable}."guid"`;
|
|
1280
|
+
sortBy = `${sTable}."number"${order}, ${sTable}."string"${order}`;
|
|
1281
|
+
sortByInner = sortBy;
|
|
1282
|
+
params[name] = sort;
|
|
1265
1283
|
break;
|
|
1266
1284
|
}
|
|
1267
|
-
if (options.reverse) {
|
|
1268
|
-
sortBy += ' DESC';
|
|
1269
|
-
}
|
|
1270
1285
|
let query;
|
|
1271
1286
|
if (queryParts.length) {
|
|
1272
1287
|
if (subquery) {
|
|
@@ -1302,8 +1317,9 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1302
1317
|
: `${ieTable}."guid"`;
|
|
1303
1318
|
query = `SELECT ${guidColumn} AS "guid"
|
|
1304
1319
|
FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ${ieTable}
|
|
1320
|
+
${sortJoinInner}
|
|
1305
1321
|
WHERE (${whereClause})
|
|
1306
|
-
ORDER BY ${
|
|
1322
|
+
ORDER BY ${sortByInner}, ${ieTable}."guid"${limit}${offset}`;
|
|
1307
1323
|
}
|
|
1308
1324
|
else {
|
|
1309
1325
|
query = `SELECT
|
|
@@ -1318,13 +1334,15 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1318
1334
|
FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ${eTable}
|
|
1319
1335
|
LEFT JOIN ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} ${dTable} ON ${eTable}."guid"=${dTable}."guid"
|
|
1320
1336
|
INNER JOIN ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}`)} ${cTable} ON ${dTable}."guid"=${cTable}."guid" AND ${dTable}."name"=${cTable}."name"
|
|
1337
|
+
${sortJoin}
|
|
1321
1338
|
INNER JOIN (
|
|
1322
1339
|
SELECT ${ieTable}."guid"
|
|
1323
1340
|
FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ${ieTable}
|
|
1341
|
+
${sortJoinInner}
|
|
1324
1342
|
WHERE (${whereClause})
|
|
1325
|
-
ORDER BY ${
|
|
1343
|
+
ORDER BY ${sortByInner}${limit}${offset}
|
|
1326
1344
|
) ${fTable} ON ${eTable}."guid"=${fTable}."guid"
|
|
1327
|
-
ORDER BY ${
|
|
1345
|
+
ORDER BY ${sortBy}, ${eTable}."guid"`;
|
|
1328
1346
|
}
|
|
1329
1347
|
}
|
|
1330
1348
|
}
|
|
@@ -1359,7 +1377,8 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1359
1377
|
: `${ieTable}."guid"`;
|
|
1360
1378
|
query = `SELECT ${guidColumn} AS "guid"
|
|
1361
1379
|
FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ${ieTable}
|
|
1362
|
-
|
|
1380
|
+
${sortJoinInner}
|
|
1381
|
+
ORDER BY ${sortByInner}, ${ieTable}."guid"${limit}${offset}`;
|
|
1363
1382
|
}
|
|
1364
1383
|
else {
|
|
1365
1384
|
if (limit || offset) {
|
|
@@ -1375,12 +1394,14 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1375
1394
|
FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ${eTable}
|
|
1376
1395
|
LEFT JOIN ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} ${dTable} ON ${eTable}."guid"=${dTable}."guid"
|
|
1377
1396
|
INNER JOIN ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}`)} ${cTable} ON ${dTable}."guid"=${cTable}."guid" AND ${dTable}."name"=${cTable}."name"
|
|
1397
|
+
${sortJoin}
|
|
1378
1398
|
INNER JOIN (
|
|
1379
1399
|
SELECT ${ieTable}."guid"
|
|
1380
1400
|
FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ${ieTable}
|
|
1381
|
-
|
|
1401
|
+
${sortJoinInner}
|
|
1402
|
+
ORDER BY ${sortByInner}${limit}${offset}
|
|
1382
1403
|
) ${fTable} ON ${eTable}."guid"=${fTable}."guid"
|
|
1383
|
-
ORDER BY ${
|
|
1404
|
+
ORDER BY ${sortBy}, ${eTable}."guid"`;
|
|
1384
1405
|
}
|
|
1385
1406
|
else {
|
|
1386
1407
|
query = `SELECT
|
|
@@ -1395,7 +1416,8 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1395
1416
|
FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ${eTable}
|
|
1396
1417
|
LEFT JOIN ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} ${dTable} ON ${eTable}."guid"=${dTable}."guid"
|
|
1397
1418
|
INNER JOIN ${PostgreSQLDriver.escape(`${this.prefix}comparisons_${etype}`)} ${cTable} ON ${dTable}."guid"=${cTable}."guid" AND ${dTable}."name"=${cTable}."name"
|
|
1398
|
-
|
|
1419
|
+
${sortJoin}
|
|
1420
|
+
ORDER BY ${sortBy}, ${eTable}."guid"`;
|
|
1399
1421
|
}
|
|
1400
1422
|
}
|
|
1401
1423
|
}
|
|
@@ -1710,6 +1732,10 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1710
1732
|
};
|
|
1711
1733
|
try {
|
|
1712
1734
|
const result = await this.saveEntityRowLike(entity, async (_entity, guid, tags, data, sdata, cdate, etype) => {
|
|
1735
|
+
if (Object.keys(data).length === 0 &&
|
|
1736
|
+
Object.keys(sdata).length === 0) {
|
|
1737
|
+
return false;
|
|
1738
|
+
}
|
|
1713
1739
|
await this.queryRun(`INSERT INTO ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ("guid", "tags", "cdate", "mdate") VALUES (decode(@guid, 'hex'), @tags, @cdate, @cdate);`, {
|
|
1714
1740
|
etypes: [etype],
|
|
1715
1741
|
params: {
|
|
@@ -1721,6 +1747,10 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1721
1747
|
await insertData(guid, data, sdata, etype);
|
|
1722
1748
|
return true;
|
|
1723
1749
|
}, async (entity, guid, tags, data, sdata, mdate, etype) => {
|
|
1750
|
+
if (Object.keys(data).length === 0 &&
|
|
1751
|
+
Object.keys(sdata).length === 0) {
|
|
1752
|
+
return false;
|
|
1753
|
+
}
|
|
1724
1754
|
const promises = [];
|
|
1725
1755
|
promises.push(this.queryRun(`SELECT 1 FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} WHERE "guid"=decode(@guid, 'hex') FOR UPDATE;`, {
|
|
1726
1756
|
etypes: [etype],
|
|
@@ -1848,8 +1878,7 @@ class PostgreSQLDriver extends nymph_1.NymphDriver {
|
|
|
1848
1878
|
this.transaction = null;
|
|
1849
1879
|
}
|
|
1850
1880
|
const nymph = this.nymph.clone();
|
|
1851
|
-
nymph.driver =
|
|
1852
|
-
nymph.driver.init(nymph);
|
|
1881
|
+
nymph.driver.transaction = transaction;
|
|
1853
1882
|
return nymph;
|
|
1854
1883
|
}
|
|
1855
1884
|
}
|