@nymphjs/driver-postgresql 1.0.0-beta.46 → 1.0.0-beta.47

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.
@@ -55,7 +55,7 @@ export default class PostgreSQLDriver extends NymphDriver {
55
55
  constructor(
56
56
  config: Partial<PostgreSQLDriverConfig>,
57
57
  link?: Pool,
58
- transaction?: PostgreSQLDriverTransaction
58
+ transaction?: PostgreSQLDriverTransaction,
59
59
  ) {
60
60
  super();
61
61
  this.config = { ...defaults, ...config };
@@ -90,7 +90,7 @@ export default class PostgreSQLDriver extends NymphDriver {
90
90
  return new PostgreSQLDriver(
91
91
  this.config,
92
92
  this.link,
93
- this.transaction ?? undefined
93
+ this.transaction ?? undefined,
94
94
  );
95
95
  }
96
96
 
@@ -100,8 +100,12 @@ export default class PostgreSQLDriver extends NymphDriver {
100
100
  }
101
101
  return new Promise((resolve, reject) =>
102
102
  this.link.connect((err, client, done) =>
103
- err ? reject(err) : resolve({ client, done })
104
- )
103
+ err
104
+ ? reject(err)
105
+ : client
106
+ ? resolve({ client, done })
107
+ : reject('No client returned from connect.'),
108
+ ),
105
109
  );
106
110
  }
107
111
 
@@ -117,8 +121,12 @@ export default class PostgreSQLDriver extends NymphDriver {
117
121
  const connection: PostgreSQLDriverConnection = await new Promise(
118
122
  (resolve, reject) =>
119
123
  this.link.connect((err, client, done) =>
120
- err ? reject(err) : resolve({ client, done })
121
- )
124
+ err
125
+ ? reject(err)
126
+ : client
127
+ ? resolve({ client, done })
128
+ : reject('No client returned from connect.'),
129
+ ),
122
130
  );
123
131
  await new Promise((resolve, reject) =>
124
132
  connection.client.query('SELECT 1;', [], (err, res) => {
@@ -126,7 +134,7 @@ export default class PostgreSQLDriver extends NymphDriver {
126
134
  reject(err);
127
135
  }
128
136
  resolve(0);
129
- })
137
+ }),
130
138
  );
131
139
  connection.done();
132
140
  }
@@ -147,7 +155,7 @@ export default class PostgreSQLDriver extends NymphDriver {
147
155
  this.postgresqlConfig.database === 'nymph'
148
156
  ) {
149
157
  throw new NotConfiguredError(
150
- "It seems the config hasn't been set up correctly."
158
+ "It seems the config hasn't been set up correctly.",
151
159
  );
152
160
  } else {
153
161
  throw new UnableToConnectError('Could not connect: ' + e?.message);
@@ -194,60 +202,60 @@ export default class PostgreSQLDriver extends NymphDriver {
194
202
  // Create the entity table.
195
203
  await this.queryRun(
196
204
  `CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(
197
- `${this.prefix}entities_${etype}`
205
+ `${this.prefix}entities_${etype}`,
198
206
  )} (
199
207
  "guid" BYTEA NOT NULL,
200
208
  "tags" TEXT[],
201
209
  "cdate" DOUBLE PRECISION NOT NULL,
202
210
  "mdate" DOUBLE PRECISION NOT NULL,
203
211
  PRIMARY KEY ("guid")
204
- ) WITH ( OIDS=FALSE );`
212
+ ) WITH ( OIDS=FALSE );`,
205
213
  );
206
214
  await this.queryRun(
207
215
  `ALTER TABLE ${PostgreSQLDriver.escape(
208
- `${this.prefix}entities_${etype}`
209
- )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`
216
+ `${this.prefix}entities_${etype}`,
217
+ )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`,
210
218
  );
211
219
  await this.queryRun(
212
220
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
213
- `${this.prefix}entities_${etype}_id_cdate`
214
- )};`
221
+ `${this.prefix}entities_${etype}_id_cdate`,
222
+ )};`,
215
223
  );
216
224
  await this.queryRun(
217
225
  `CREATE INDEX ${PostgreSQLDriver.escape(
218
- `${this.prefix}entities_${etype}_id_cdate`
226
+ `${this.prefix}entities_${etype}_id_cdate`,
219
227
  )} ON ${PostgreSQLDriver.escape(
220
- `${this.prefix}entities_${etype}`
221
- )} USING btree ("cdate");`
228
+ `${this.prefix}entities_${etype}`,
229
+ )} USING btree ("cdate");`,
222
230
  );
223
231
  await this.queryRun(
224
232
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
225
- `${this.prefix}entities_${etype}_id_mdate`
226
- )};`
233
+ `${this.prefix}entities_${etype}_id_mdate`,
234
+ )};`,
227
235
  );
228
236
  await this.queryRun(
229
237
  `CREATE INDEX ${PostgreSQLDriver.escape(
230
- `${this.prefix}entities_${etype}_id_mdate`
238
+ `${this.prefix}entities_${etype}_id_mdate`,
231
239
  )} ON ${PostgreSQLDriver.escape(
232
- `${this.prefix}entities_${etype}`
233
- )} USING btree ("mdate");`
240
+ `${this.prefix}entities_${etype}`,
241
+ )} USING btree ("mdate");`,
234
242
  );
235
243
  await this.queryRun(
236
244
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
237
- `${this.prefix}entities_${etype}_id_tags`
238
- )};`
245
+ `${this.prefix}entities_${etype}_id_tags`,
246
+ )};`,
239
247
  );
240
248
  await this.queryRun(
241
249
  `CREATE INDEX ${PostgreSQLDriver.escape(
242
- `${this.prefix}entities_${etype}_id_tags`
250
+ `${this.prefix}entities_${etype}_id_tags`,
243
251
  )} ON ${PostgreSQLDriver.escape(
244
- `${this.prefix}entities_${etype}`
245
- )} USING gin ("tags");`
252
+ `${this.prefix}entities_${etype}`,
253
+ )} USING gin ("tags");`,
246
254
  );
247
255
  // Create the data table.
248
256
  await this.queryRun(
249
257
  `CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(
250
- `${this.prefix}data_${etype}`
258
+ `${this.prefix}data_${etype}`,
251
259
  )} (
252
260
  "guid" BYTEA NOT NULL,
253
261
  "name" TEXT NOT NULL,
@@ -255,67 +263,67 @@ export default class PostgreSQLDriver extends NymphDriver {
255
263
  PRIMARY KEY ("guid", "name"),
256
264
  FOREIGN KEY ("guid")
257
265
  REFERENCES ${PostgreSQLDriver.escape(
258
- `${this.prefix}entities_${etype}`
266
+ `${this.prefix}entities_${etype}`,
259
267
  )} ("guid") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE
260
- ) WITH ( OIDS=FALSE );`
268
+ ) WITH ( OIDS=FALSE );`,
261
269
  );
262
270
  await this.queryRun(
263
271
  `ALTER TABLE ${PostgreSQLDriver.escape(
264
- `${this.prefix}data_${etype}`
265
- )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`
272
+ `${this.prefix}data_${etype}`,
273
+ )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`,
266
274
  );
267
275
  await this.queryRun(
268
276
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
269
- `${this.prefix}data_${etype}_id_guid`
270
- )};`
277
+ `${this.prefix}data_${etype}_id_guid`,
278
+ )};`,
271
279
  );
272
280
  await this.queryRun(
273
281
  `CREATE INDEX ${PostgreSQLDriver.escape(
274
- `${this.prefix}data_${etype}_id_guid`
282
+ `${this.prefix}data_${etype}_id_guid`,
275
283
  )} ON ${PostgreSQLDriver.escape(
276
- `${this.prefix}data_${etype}`
277
- )} USING btree ("guid");`
284
+ `${this.prefix}data_${etype}`,
285
+ )} USING btree ("guid");`,
278
286
  );
279
287
  await this.queryRun(
280
288
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
281
- `${this.prefix}data_${etype}_id_name`
282
- )};`
289
+ `${this.prefix}data_${etype}_id_name`,
290
+ )};`,
283
291
  );
284
292
  await this.queryRun(
285
293
  `CREATE INDEX ${PostgreSQLDriver.escape(
286
- `${this.prefix}data_${etype}_id_name`
294
+ `${this.prefix}data_${etype}_id_name`,
287
295
  )} ON ${PostgreSQLDriver.escape(
288
- `${this.prefix}data_${etype}`
289
- )} USING btree ("name");`
296
+ `${this.prefix}data_${etype}`,
297
+ )} USING btree ("name");`,
290
298
  );
291
299
  await this.queryRun(
292
300
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
293
- `${this.prefix}data_${etype}_id_guid_name__user`
294
- )};`
301
+ `${this.prefix}data_${etype}_id_guid_name__user`,
302
+ )};`,
295
303
  );
296
304
  await this.queryRun(
297
305
  `CREATE INDEX ${PostgreSQLDriver.escape(
298
- `${this.prefix}data_${etype}_id_guid_name__user`
306
+ `${this.prefix}data_${etype}_id_guid_name__user`,
299
307
  )} ON ${PostgreSQLDriver.escape(
300
- `${this.prefix}data_${etype}`
301
- )} USING btree ("guid") WHERE "name" = 'user'::text;`
308
+ `${this.prefix}data_${etype}`,
309
+ )} USING btree ("guid") WHERE "name" = 'user'::text;`,
302
310
  );
303
311
  await this.queryRun(
304
312
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
305
- `${this.prefix}data_${etype}_id_guid_name__group`
306
- )};`
313
+ `${this.prefix}data_${etype}_id_guid_name__group`,
314
+ )};`,
307
315
  );
308
316
  await this.queryRun(
309
317
  `CREATE INDEX ${PostgreSQLDriver.escape(
310
- `${this.prefix}data_${etype}_id_guid_name__group`
318
+ `${this.prefix}data_${etype}_id_guid_name__group`,
311
319
  )} ON ${PostgreSQLDriver.escape(
312
- `${this.prefix}data_${etype}`
313
- )} USING btree ("guid") WHERE "name" = 'group'::text;`
320
+ `${this.prefix}data_${etype}`,
321
+ )} USING btree ("guid") WHERE "name" = 'group'::text;`,
314
322
  );
315
323
  // Create the data comparisons table.
316
324
  await this.queryRun(
317
325
  `CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(
318
- `${this.prefix}comparisons_${etype}`
326
+ `${this.prefix}comparisons_${etype}`,
319
327
  )} (
320
328
  "guid" BYTEA NOT NULL,
321
329
  "name" TEXT NOT NULL,
@@ -325,67 +333,67 @@ export default class PostgreSQLDriver extends NymphDriver {
325
333
  PRIMARY KEY ("guid", "name"),
326
334
  FOREIGN KEY ("guid")
327
335
  REFERENCES ${PostgreSQLDriver.escape(
328
- `${this.prefix}entities_${etype}`
336
+ `${this.prefix}entities_${etype}`,
329
337
  )} ("guid") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE
330
- ) WITH ( OIDS=FALSE );`
338
+ ) WITH ( OIDS=FALSE );`,
331
339
  );
332
340
  await this.queryRun(
333
341
  `ALTER TABLE ${PostgreSQLDriver.escape(
334
- `${this.prefix}comparisons_${etype}`
335
- )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`
342
+ `${this.prefix}comparisons_${etype}`,
343
+ )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`,
336
344
  );
337
345
  await this.queryRun(
338
346
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
339
- `${this.prefix}comparisons_${etype}_id_guid`
340
- )};`
347
+ `${this.prefix}comparisons_${etype}_id_guid`,
348
+ )};`,
341
349
  );
342
350
  await this.queryRun(
343
351
  `CREATE INDEX ${PostgreSQLDriver.escape(
344
- `${this.prefix}comparisons_${etype}_id_guid`
352
+ `${this.prefix}comparisons_${etype}_id_guid`,
345
353
  )} ON ${PostgreSQLDriver.escape(
346
- `${this.prefix}comparisons_${etype}`
347
- )} USING btree ("guid");`
354
+ `${this.prefix}comparisons_${etype}`,
355
+ )} USING btree ("guid");`,
348
356
  );
349
357
  await this.queryRun(
350
358
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
351
- `${this.prefix}comparisons_${etype}_id_name`
352
- )};`
359
+ `${this.prefix}comparisons_${etype}_id_name`,
360
+ )};`,
353
361
  );
354
362
  await this.queryRun(
355
363
  `CREATE INDEX ${PostgreSQLDriver.escape(
356
- `${this.prefix}comparisons_${etype}_id_name`
364
+ `${this.prefix}comparisons_${etype}_id_name`,
357
365
  )} ON ${PostgreSQLDriver.escape(
358
- `${this.prefix}comparisons_${etype}`
359
- )} USING btree ("name");`
366
+ `${this.prefix}comparisons_${etype}`,
367
+ )} USING btree ("name");`,
360
368
  );
361
369
  await this.queryRun(
362
370
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
363
- `${this.prefix}comparisons_${etype}_id_guid_name_truthy`
364
- )};`
371
+ `${this.prefix}comparisons_${etype}_id_guid_name_truthy`,
372
+ )};`,
365
373
  );
366
374
  await this.queryRun(
367
375
  `CREATE INDEX ${PostgreSQLDriver.escape(
368
- `${this.prefix}comparisons_${etype}_id_guid_name_truthy`
376
+ `${this.prefix}comparisons_${etype}_id_guid_name_truthy`,
369
377
  )} ON ${PostgreSQLDriver.escape(
370
- `${this.prefix}comparisons_${etype}`
371
- )} USING btree ("guid", "name") WHERE "truthy" = TRUE;`
378
+ `${this.prefix}comparisons_${etype}`,
379
+ )} USING btree ("guid", "name") WHERE "truthy" = TRUE;`,
372
380
  );
373
381
  await this.queryRun(
374
382
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
375
- `${this.prefix}comparisons_${etype}_id_guid_name_falsy`
376
- )};`
383
+ `${this.prefix}comparisons_${etype}_id_guid_name_falsy`,
384
+ )};`,
377
385
  );
378
386
  await this.queryRun(
379
387
  `CREATE INDEX ${PostgreSQLDriver.escape(
380
- `${this.prefix}comparisons_${etype}_id_guid_name_falsy`
388
+ `${this.prefix}comparisons_${etype}_id_guid_name_falsy`,
381
389
  )} ON ${PostgreSQLDriver.escape(
382
- `${this.prefix}comparisons_${etype}`
383
- )} USING btree ("guid", "name") WHERE "truthy" <> TRUE;`
390
+ `${this.prefix}comparisons_${etype}`,
391
+ )} USING btree ("guid", "name") WHERE "truthy" <> TRUE;`,
384
392
  );
385
393
  // Create the references table.
386
394
  await this.queryRun(
387
395
  `CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(
388
- `${this.prefix}references_${etype}`
396
+ `${this.prefix}references_${etype}`,
389
397
  )} (
390
398
  "guid" BYTEA NOT NULL,
391
399
  "name" TEXT NOT NULL,
@@ -393,66 +401,66 @@ export default class PostgreSQLDriver extends NymphDriver {
393
401
  PRIMARY KEY ("guid", "name", "reference"),
394
402
  FOREIGN KEY ("guid")
395
403
  REFERENCES ${PostgreSQLDriver.escape(
396
- `${this.prefix}entities_${etype}`
404
+ `${this.prefix}entities_${etype}`,
397
405
  )} ("guid") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE
398
- ) WITH ( OIDS=FALSE );`
406
+ ) WITH ( OIDS=FALSE );`,
399
407
  );
400
408
  await this.queryRun(
401
409
  `ALTER TABLE ${PostgreSQLDriver.escape(
402
- `${this.prefix}references_${etype}`
403
- )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`
410
+ `${this.prefix}references_${etype}`,
411
+ )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`,
404
412
  );
405
413
  await this.queryRun(
406
414
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
407
- `${this.prefix}references_${etype}_id_guid`
408
- )};`
415
+ `${this.prefix}references_${etype}_id_guid`,
416
+ )};`,
409
417
  );
410
418
  await this.queryRun(
411
419
  `CREATE INDEX ${PostgreSQLDriver.escape(
412
- `${this.prefix}references_${etype}_id_guid`
420
+ `${this.prefix}references_${etype}_id_guid`,
413
421
  )} ON ${PostgreSQLDriver.escape(
414
- `${this.prefix}references_${etype}`
415
- )} USING btree ("guid");`
422
+ `${this.prefix}references_${etype}`,
423
+ )} USING btree ("guid");`,
416
424
  );
417
425
  await this.queryRun(
418
426
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
419
- `${this.prefix}references_${etype}_id_name`
420
- )};`
427
+ `${this.prefix}references_${etype}_id_name`,
428
+ )};`,
421
429
  );
422
430
  await this.queryRun(
423
431
  `CREATE INDEX ${PostgreSQLDriver.escape(
424
- `${this.prefix}references_${etype}_id_name`
432
+ `${this.prefix}references_${etype}_id_name`,
425
433
  )} ON ${PostgreSQLDriver.escape(
426
- `${this.prefix}references_${etype}`
427
- )} USING btree ("name");`
434
+ `${this.prefix}references_${etype}`,
435
+ )} USING btree ("name");`,
428
436
  );
429
437
  await this.queryRun(
430
438
  `DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(
431
- `${this.prefix}references_${etype}_id_reference`
432
- )};`
439
+ `${this.prefix}references_${etype}_id_reference`,
440
+ )};`,
433
441
  );
434
442
  await this.queryRun(
435
443
  `CREATE INDEX ${PostgreSQLDriver.escape(
436
- `${this.prefix}references_${etype}_id_reference`
444
+ `${this.prefix}references_${etype}_id_reference`,
437
445
  )} ON ${PostgreSQLDriver.escape(
438
- `${this.prefix}references_${etype}`
439
- )} USING btree ("reference");`
446
+ `${this.prefix}references_${etype}`,
447
+ )} USING btree ("reference");`,
440
448
  );
441
449
  } else {
442
450
  // Create the UID table.
443
451
  await this.queryRun(
444
452
  `CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(
445
- `${this.prefix}uids`
453
+ `${this.prefix}uids`,
446
454
  )} (
447
455
  "name" TEXT NOT NULL,
448
456
  "cur_uid" BIGINT NOT NULL,
449
457
  PRIMARY KEY ("name")
450
- ) WITH ( OIDS = FALSE );`
458
+ ) WITH ( OIDS = FALSE );`,
451
459
  );
452
460
  await this.queryRun(
453
461
  `ALTER TABLE ${PostgreSQLDriver.escape(
454
- `${this.prefix}uids`
455
- )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`
462
+ `${this.prefix}uids`,
463
+ )} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`,
456
464
  );
457
465
  }
458
466
  return true;
@@ -460,7 +468,7 @@ export default class PostgreSQLDriver extends NymphDriver {
460
468
 
461
469
  private translateQuery(
462
470
  origQuery: string,
463
- origParams: { [k: string]: any }
471
+ origParams: { [k: string]: any },
464
472
  ): { query: string; params: any[] } {
465
473
  const params: any[] = [];
466
474
  let query = origQuery;
@@ -480,7 +488,7 @@ export default class PostgreSQLDriver extends NymphDriver {
480
488
  private async query<T extends () => any>(
481
489
  runQuery: T,
482
490
  query: string,
483
- etypes: string[] = []
491
+ etypes: string[] = [],
484
492
  // @ts-ignore: The return type of T is a promise.
485
493
  ): ReturnType<T> {
486
494
  try {
@@ -497,7 +505,7 @@ export default class PostgreSQLDriver extends NymphDriver {
497
505
  } catch (e2: any) {
498
506
  throw new QueryFailedError(
499
507
  'Query failed: ' + e2?.code + ' - ' + e2?.message,
500
- query
508
+ query,
501
509
  );
502
510
  }
503
511
  } else {
@@ -514,11 +522,11 @@ export default class PostgreSQLDriver extends NymphDriver {
514
522
  }: {
515
523
  etypes?: string[];
516
524
  params?: { [k: string]: any };
517
- } = {}
525
+ } = {},
518
526
  ) {
519
527
  const { query: newQuery, params: newParams } = this.translateQuery(
520
528
  query,
521
- params
529
+ params,
522
530
  );
523
531
  return this.query(
524
532
  async () => {
@@ -529,17 +537,17 @@ export default class PostgreSQLDriver extends NymphDriver {
529
537
  .query(newQuery, newParams)
530
538
  .then(
531
539
  (results) => resolve(results),
532
- (error) => reject(error)
540
+ (error) => reject(error),
533
541
  );
534
542
  } catch (e) {
535
543
  reject(e);
536
544
  }
537
- }
545
+ },
538
546
  );
539
547
  return results.rows;
540
548
  },
541
549
  `${query} -- ${JSON.stringify(params)}`,
542
- etypes
550
+ etypes,
543
551
  );
544
552
  }
545
553
 
@@ -551,11 +559,11 @@ export default class PostgreSQLDriver extends NymphDriver {
551
559
  }: {
552
560
  etypes?: string[];
553
561
  params?: { [k: string]: any };
554
- } = {}
562
+ } = {},
555
563
  ) {
556
564
  const { query: newQuery, params: newParams } = this.translateQuery(
557
565
  query,
558
- params
566
+ params,
559
567
  );
560
568
  return this.query(
561
569
  async () => {
@@ -566,17 +574,17 @@ export default class PostgreSQLDriver extends NymphDriver {
566
574
  .query(newQuery, newParams)
567
575
  .then(
568
576
  (results) => resolve(results),
569
- (error) => reject(error)
577
+ (error) => reject(error),
570
578
  );
571
579
  } catch (e) {
572
580
  reject(e);
573
581
  }
574
- }
582
+ },
575
583
  );
576
584
  return results.rows[0];
577
585
  },
578
586
  `${query} -- ${JSON.stringify(params)}`,
579
- etypes
587
+ etypes,
580
588
  );
581
589
  }
582
590
 
@@ -588,11 +596,11 @@ export default class PostgreSQLDriver extends NymphDriver {
588
596
  }: {
589
597
  etypes?: string[];
590
598
  params?: { [k: string]: any };
591
- } = {}
599
+ } = {},
592
600
  ) {
593
601
  const { query: newQuery, params: newParams } = this.translateQuery(
594
602
  query,
595
- params
603
+ params,
596
604
  );
597
605
  return this.query(
598
606
  async () => {
@@ -603,24 +611,24 @@ export default class PostgreSQLDriver extends NymphDriver {
603
611
  .query(newQuery, newParams)
604
612
  .then(
605
613
  (results) => resolve(results),
606
- (error) => reject(error)
614
+ (error) => reject(error),
607
615
  );
608
616
  } catch (e) {
609
617
  reject(e);
610
618
  }
611
- }
619
+ },
612
620
  );
613
621
  return { rowCount: results.rowCount ?? 0 };
614
622
  },
615
623
  `${query} -- ${JSON.stringify(params)}`,
616
- etypes
624
+ etypes,
617
625
  );
618
626
  }
619
627
 
620
628
  public async commit(name: string) {
621
629
  if (name == null || typeof name !== 'string' || name.length === 0) {
622
630
  throw new InvalidParametersError(
623
- 'Transaction commit attempted without a name.'
631
+ 'Transaction commit attempted without a name.',
624
632
  );
625
633
  }
626
634
  if (!this.transaction || this.transaction.count === 0) {
@@ -640,7 +648,7 @@ export default class PostgreSQLDriver extends NymphDriver {
640
648
 
641
649
  public async deleteEntityByID(
642
650
  guid: string,
643
- className?: EntityConstructor | string | null
651
+ className?: EntityConstructor | string | null,
644
652
  ) {
645
653
  let EntityClass: EntityConstructor;
646
654
  if (typeof className === 'string' || className == null) {
@@ -654,47 +662,47 @@ export default class PostgreSQLDriver extends NymphDriver {
654
662
  try {
655
663
  await this.queryRun(
656
664
  `DELETE FROM ${PostgreSQLDriver.escape(
657
- `${this.prefix}entities_${etype}`
665
+ `${this.prefix}entities_${etype}`,
658
666
  )} WHERE "guid"=decode(@guid, 'hex');`,
659
667
  {
660
668
  etypes: [etype],
661
669
  params: {
662
670
  guid,
663
671
  },
664
- }
672
+ },
665
673
  );
666
674
  await this.queryRun(
667
675
  `DELETE FROM ${PostgreSQLDriver.escape(
668
- `${this.prefix}data_${etype}`
676
+ `${this.prefix}data_${etype}`,
669
677
  )} WHERE "guid"=decode(@guid, 'hex');`,
670
678
  {
671
679
  etypes: [etype],
672
680
  params: {
673
681
  guid,
674
682
  },
675
- }
683
+ },
676
684
  );
677
685
  await this.queryRun(
678
686
  `DELETE FROM ${PostgreSQLDriver.escape(
679
- `${this.prefix}comparisons_${etype}`
687
+ `${this.prefix}comparisons_${etype}`,
680
688
  )} WHERE "guid"=decode(@guid, 'hex');`,
681
689
  {
682
690
  etypes: [etype],
683
691
  params: {
684
692
  guid,
685
693
  },
686
- }
694
+ },
687
695
  );
688
696
  await this.queryRun(
689
697
  `DELETE FROM ${PostgreSQLDriver.escape(
690
- `${this.prefix}references_${etype}`
698
+ `${this.prefix}references_${etype}`,
691
699
  )} WHERE "guid"=decode(@guid, 'hex');`,
692
700
  {
693
701
  etypes: [etype],
694
702
  params: {
695
703
  guid,
696
704
  },
697
- }
705
+ },
698
706
  );
699
707
  await this.commit('nymph-delete');
700
708
  // Remove any cached versions of this entity.
@@ -714,13 +722,13 @@ export default class PostgreSQLDriver extends NymphDriver {
714
722
  }
715
723
  await this.queryRun(
716
724
  `DELETE FROM ${PostgreSQLDriver.escape(
717
- `${this.prefix}uids`
725
+ `${this.prefix}uids`,
718
726
  )} WHERE "name"=@name;`,
719
727
  {
720
728
  params: {
721
729
  name,
722
730
  },
723
- }
731
+ },
724
732
  );
725
733
  return true;
726
734
  }
@@ -741,8 +749,8 @@ export default class PostgreSQLDriver extends NymphDriver {
741
749
  // Export UIDs.
742
750
  let uids = await this.queryIter(
743
751
  `SELECT * FROM ${PostgreSQLDriver.escape(
744
- `${this.prefix}uids`
745
- )} ORDER BY "name";`
752
+ `${this.prefix}uids`,
753
+ )} ORDER BY "name";`,
746
754
  );
747
755
  for (const uid of uids) {
748
756
  writeLine(`<${uid.name}>[${uid.cur_uid}]`);
@@ -756,7 +764,7 @@ export default class PostgreSQLDriver extends NymphDriver {
756
764
 
757
765
  // Get the etypes.
758
766
  const tables = await this.queryIter(
759
- 'SELECT relname FROM pg_stat_user_tables ORDER BY relname;'
767
+ 'SELECT relname FROM pg_stat_user_tables ORDER BY relname;',
760
768
  );
761
769
  const etypes = [];
762
770
  for (const tableRow of tables) {
@@ -773,12 +781,12 @@ export default class PostgreSQLDriver extends NymphDriver {
773
781
  `SELECT encode(e."guid", 'hex') AS "guid", e."tags", e."cdate", e."mdate", d."name" AS "dname", d."value" AS "dvalue", c."string", c."number"
774
782
  FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} e
775
783
  LEFT JOIN ${PostgreSQLDriver.escape(
776
- `${this.prefix}data_${etype}`
784
+ `${this.prefix}data_${etype}`,
777
785
  )} d ON e."guid"=d."guid"
778
786
  INNER JOIN ${PostgreSQLDriver.escape(
779
- `${this.prefix}comparisons_${etype}`
787
+ `${this.prefix}comparisons_${etype}`,
780
788
  )} c ON d."guid"=c."guid" AND d."name"=c."name"
781
- ORDER BY e."guid";`
789
+ ORDER BY e."guid";`,
782
790
  )
783
791
  )[Symbol.iterator]();
784
792
  let datum = dataIterator.next();
@@ -831,7 +839,7 @@ export default class PostgreSQLDriver extends NymphDriver {
831
839
  params: { [k: string]: any } = {},
832
840
  subquery = false,
833
841
  tableSuffix = '',
834
- etypes: string[] = []
842
+ etypes: string[] = [],
835
843
  ) {
836
844
  if (typeof options.class?.alterOptions === 'function') {
837
845
  options = options.class.alterOptions(options);
@@ -928,7 +936,7 @@ export default class PostgreSQLDriver extends NymphDriver {
928
936
  ieTable +
929
937
  '."guid" IN (SELECT "guid" FROM ' +
930
938
  PostgreSQLDriver.escape(
931
- this.prefix + 'comparisons_' + etype
939
+ this.prefix + 'comparisons_' + etype,
932
940
  ) +
933
941
  ' WHERE "name"=@' +
934
942
  name +
@@ -978,7 +986,7 @@ export default class PostgreSQLDriver extends NymphDriver {
978
986
  ieTable +
979
987
  '."guid" IN (SELECT "guid" FROM ' +
980
988
  PostgreSQLDriver.escape(
981
- this.prefix + 'comparisons_' + etype
989
+ this.prefix + 'comparisons_' + etype,
982
990
  ) +
983
991
  ' WHERE "name"=@' +
984
992
  name +
@@ -998,7 +1006,7 @@ export default class PostgreSQLDriver extends NymphDriver {
998
1006
  ieTable +
999
1007
  '."guid" IN (SELECT "guid" FROM ' +
1000
1008
  PostgreSQLDriver.escape(
1001
- this.prefix + 'comparisons_' + etype
1009
+ this.prefix + 'comparisons_' + etype,
1002
1010
  ) +
1003
1011
  ' WHERE "name"=@' +
1004
1012
  name +
@@ -1100,7 +1108,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1100
1108
  ieTable +
1101
1109
  '."guid" IN (SELECT "guid" FROM ' +
1102
1110
  PostgreSQLDriver.escape(
1103
- this.prefix + 'comparisons_' + etype
1111
+ this.prefix + 'comparisons_' + etype,
1104
1112
  ) +
1105
1113
  ' WHERE "name"=@' +
1106
1114
  name +
@@ -1165,7 +1173,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1165
1173
  ieTable +
1166
1174
  '."guid" IN (SELECT "guid" FROM ' +
1167
1175
  PostgreSQLDriver.escape(
1168
- this.prefix + 'comparisons_' + etype
1176
+ this.prefix + 'comparisons_' + etype,
1169
1177
  ) +
1170
1178
  ' WHERE "name"=@' +
1171
1179
  name +
@@ -1217,7 +1225,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1217
1225
  ieTable +
1218
1226
  '."guid" IN (SELECT "guid" FROM ' +
1219
1227
  PostgreSQLDriver.escape(
1220
- this.prefix + 'comparisons_' + etype
1228
+ this.prefix + 'comparisons_' + etype,
1221
1229
  ) +
1222
1230
  ' WHERE "name"=@' +
1223
1231
  name +
@@ -1269,7 +1277,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1269
1277
  ieTable +
1270
1278
  '."guid" IN (SELECT "guid" FROM ' +
1271
1279
  PostgreSQLDriver.escape(
1272
- this.prefix + 'comparisons_' + etype
1280
+ this.prefix + 'comparisons_' + etype,
1273
1281
  ) +
1274
1282
  ' WHERE "name"=@' +
1275
1283
  name +
@@ -1321,7 +1329,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1321
1329
  ieTable +
1322
1330
  '."guid" IN (SELECT "guid" FROM ' +
1323
1331
  PostgreSQLDriver.escape(
1324
- this.prefix + 'comparisons_' + etype
1332
+ this.prefix + 'comparisons_' + etype,
1325
1333
  ) +
1326
1334
  ' WHERE "name"=@' +
1327
1335
  name +
@@ -1373,7 +1381,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1373
1381
  ieTable +
1374
1382
  '."guid" IN (SELECT "guid" FROM ' +
1375
1383
  PostgreSQLDriver.escape(
1376
- this.prefix + 'comparisons_' + etype
1384
+ this.prefix + 'comparisons_' + etype,
1377
1385
  ) +
1378
1386
  ' WHERE "name"=@' +
1379
1387
  name +
@@ -1427,7 +1435,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1427
1435
  ieTable +
1428
1436
  '."guid" IN (SELECT "guid" FROM ' +
1429
1437
  PostgreSQLDriver.escape(
1430
- this.prefix + 'comparisons_' + etype
1438
+ this.prefix + 'comparisons_' + etype,
1431
1439
  ) +
1432
1440
  ' WHERE "name"=@' +
1433
1441
  name +
@@ -1481,7 +1489,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1481
1489
  ieTable +
1482
1490
  '."guid" IN (SELECT "guid" FROM ' +
1483
1491
  PostgreSQLDriver.escape(
1484
- this.prefix + 'comparisons_' + etype
1492
+ this.prefix + 'comparisons_' + etype,
1485
1493
  ) +
1486
1494
  ' WHERE "name"=@' +
1487
1495
  name +
@@ -1535,7 +1543,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1535
1543
  ieTable +
1536
1544
  '."guid" IN (SELECT "guid" FROM ' +
1537
1545
  PostgreSQLDriver.escape(
1538
- this.prefix + 'comparisons_' + etype
1546
+ this.prefix + 'comparisons_' + etype,
1539
1547
  ) +
1540
1548
  ' WHERE "name"=@' +
1541
1549
  name +
@@ -1586,7 +1594,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1586
1594
  params,
1587
1595
  true,
1588
1596
  tableSuffix,
1589
- etypes
1597
+ etypes,
1590
1598
  );
1591
1599
  if (curQuery) {
1592
1600
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -1601,7 +1609,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1601
1609
  case '!qref':
1602
1610
  const [qrefOptions, ...qrefSelectors] = curValue[1] as [
1603
1611
  Options,
1604
- ...FormattedSelector[]
1612
+ ...FormattedSelector[],
1605
1613
  ];
1606
1614
  const QrefEntityClass = qrefOptions.class as EntityConstructor;
1607
1615
  etypes.push(QrefEntityClass.ETYPE);
@@ -1613,7 +1621,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1613
1621
  params,
1614
1622
  false,
1615
1623
  makeTableSuffix(),
1616
- etypes
1624
+ etypes,
1617
1625
  );
1618
1626
  if (curQuery) {
1619
1627
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -1634,7 +1642,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1634
1642
  }
1635
1643
  }
1636
1644
  return curQuery;
1637
- }
1645
+ },
1638
1646
  );
1639
1647
 
1640
1648
  let sortBy: string;
@@ -1656,7 +1664,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1656
1664
  sortJoin = `LEFT JOIN (
1657
1665
  SELECT "guid", "string", "number"
1658
1666
  FROM ${PostgreSQLDriver.escape(
1659
- this.prefix + 'comparisons_' + etype
1667
+ this.prefix + 'comparisons_' + etype,
1660
1668
  )}
1661
1669
  WHERE "name"=@${name}
1662
1670
  ORDER BY "number"${order}, "string"${order}
@@ -1664,7 +1672,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1664
1672
  sortJoinInner = `LEFT JOIN (
1665
1673
  SELECT "guid", "string", "number"
1666
1674
  FROM ${PostgreSQLDriver.escape(
1667
- this.prefix + 'comparisons_' + etype
1675
+ this.prefix + 'comparisons_' + etype,
1668
1676
  )}
1669
1677
  WHERE "name"=@${name}
1670
1678
  ORDER BY "number"${order}, "string"${order}
@@ -1683,13 +1691,13 @@ export default class PostgreSQLDriver extends NymphDriver {
1683
1691
  let limit = '';
1684
1692
  if ('limit' in options) {
1685
1693
  limit = ` LIMIT ${Math.floor(
1686
- isNaN(Number(options.limit)) ? 0 : Number(options.limit)
1694
+ isNaN(Number(options.limit)) ? 0 : Number(options.limit),
1687
1695
  )}`;
1688
1696
  }
1689
1697
  let offset = '';
1690
1698
  if ('offset' in options) {
1691
1699
  offset = ` OFFSET ${Math.floor(
1692
- isNaN(Number(options.offset)) ? 0 : Number(options.offset)
1700
+ isNaN(Number(options.offset)) ? 0 : Number(options.offset),
1693
1701
  )}`;
1694
1702
  }
1695
1703
  const whereClause = queryParts.join(') AND (');
@@ -1698,14 +1706,14 @@ export default class PostgreSQLDriver extends NymphDriver {
1698
1706
  query = `SELECT COUNT(${countTable}."guid") AS "count" FROM (
1699
1707
  SELECT COUNT(${ieTable}."guid") AS "guid"
1700
1708
  FROM ${PostgreSQLDriver.escape(
1701
- `${this.prefix}entities_${etype}`
1709
+ `${this.prefix}entities_${etype}`,
1702
1710
  )} ${ieTable}
1703
1711
  WHERE (${whereClause})${limit}${offset}
1704
1712
  ) ${countTable}`;
1705
1713
  } else {
1706
1714
  query = `SELECT COUNT(${ieTable}."guid") AS "count"
1707
1715
  FROM ${PostgreSQLDriver.escape(
1708
- `${this.prefix}entities_${etype}`
1716
+ `${this.prefix}entities_${etype}`,
1709
1717
  )} ${ieTable}
1710
1718
  WHERE (${whereClause})`;
1711
1719
  }
@@ -1716,7 +1724,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1716
1724
  : `${ieTable}."guid"`;
1717
1725
  query = `SELECT ${guidColumn} AS "guid"
1718
1726
  FROM ${PostgreSQLDriver.escape(
1719
- `${this.prefix}entities_${etype}`
1727
+ `${this.prefix}entities_${etype}`,
1720
1728
  )} ${ieTable}
1721
1729
  ${sortJoinInner}
1722
1730
  WHERE (${whereClause})
@@ -1732,19 +1740,19 @@ export default class PostgreSQLDriver extends NymphDriver {
1732
1740
  ${cTable}."string",
1733
1741
  ${cTable}."number"
1734
1742
  FROM ${PostgreSQLDriver.escape(
1735
- `${this.prefix}entities_${etype}`
1743
+ `${this.prefix}entities_${etype}`,
1736
1744
  )} ${eTable}
1737
1745
  LEFT JOIN ${PostgreSQLDriver.escape(
1738
- `${this.prefix}data_${etype}`
1746
+ `${this.prefix}data_${etype}`,
1739
1747
  )} ${dTable} ON ${eTable}."guid"=${dTable}."guid"
1740
1748
  INNER JOIN ${PostgreSQLDriver.escape(
1741
- `${this.prefix}comparisons_${etype}`
1749
+ `${this.prefix}comparisons_${etype}`,
1742
1750
  )} ${cTable} ON ${dTable}."guid"=${cTable}."guid" AND ${dTable}."name"=${cTable}."name"
1743
1751
  ${sortJoin}
1744
1752
  INNER JOIN (
1745
1753
  SELECT ${ieTable}."guid"
1746
1754
  FROM ${PostgreSQLDriver.escape(
1747
- `${this.prefix}entities_${etype}`
1755
+ `${this.prefix}entities_${etype}`,
1748
1756
  )} ${ieTable}
1749
1757
  ${sortJoinInner}
1750
1758
  WHERE (${whereClause})
@@ -1760,13 +1768,13 @@ export default class PostgreSQLDriver extends NymphDriver {
1760
1768
  let limit = '';
1761
1769
  if ('limit' in options) {
1762
1770
  limit = ` LIMIT ${Math.floor(
1763
- isNaN(Number(options.limit)) ? 0 : Number(options.limit)
1771
+ isNaN(Number(options.limit)) ? 0 : Number(options.limit),
1764
1772
  )}`;
1765
1773
  }
1766
1774
  let offset = '';
1767
1775
  if ('offset' in options) {
1768
1776
  offset = ` OFFSET ${Math.floor(
1769
- isNaN(Number(options.offset)) ? 0 : Number(options.offset)
1777
+ isNaN(Number(options.offset)) ? 0 : Number(options.offset),
1770
1778
  )}`;
1771
1779
  }
1772
1780
  if (options.return === 'count') {
@@ -1774,13 +1782,13 @@ export default class PostgreSQLDriver extends NymphDriver {
1774
1782
  query = `SELECT COUNT(${countTable}."guid") AS "count" FROM (
1775
1783
  SELECT COUNT(${ieTable}."guid") AS "guid"
1776
1784
  FROM ${PostgreSQLDriver.escape(
1777
- `${this.prefix}entities_${etype}`
1785
+ `${this.prefix}entities_${etype}`,
1778
1786
  )} ${ieTable}${limit}${offset}
1779
1787
  ) ${countTable}`;
1780
1788
  } else {
1781
1789
  query = `SELECT COUNT(${ieTable}."guid") AS "count"
1782
1790
  FROM ${PostgreSQLDriver.escape(
1783
- `${this.prefix}entities_${etype}`
1791
+ `${this.prefix}entities_${etype}`,
1784
1792
  )} ${ieTable}`;
1785
1793
  }
1786
1794
  } else if (options.return === 'guid') {
@@ -1790,7 +1798,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1790
1798
  : `${ieTable}."guid"`;
1791
1799
  query = `SELECT ${guidColumn} AS "guid"
1792
1800
  FROM ${PostgreSQLDriver.escape(
1793
- `${this.prefix}entities_${etype}`
1801
+ `${this.prefix}entities_${etype}`,
1794
1802
  )} ${ieTable}
1795
1803
  ${sortJoinInner}
1796
1804
  ORDER BY ${sortByInner}, ${ieTable}."guid"${limit}${offset}`;
@@ -1806,19 +1814,19 @@ export default class PostgreSQLDriver extends NymphDriver {
1806
1814
  ${cTable}."string",
1807
1815
  ${cTable}."number"
1808
1816
  FROM ${PostgreSQLDriver.escape(
1809
- `${this.prefix}entities_${etype}`
1817
+ `${this.prefix}entities_${etype}`,
1810
1818
  )} ${eTable}
1811
1819
  LEFT JOIN ${PostgreSQLDriver.escape(
1812
- `${this.prefix}data_${etype}`
1820
+ `${this.prefix}data_${etype}`,
1813
1821
  )} ${dTable} ON ${eTable}."guid"=${dTable}."guid"
1814
1822
  INNER JOIN ${PostgreSQLDriver.escape(
1815
- `${this.prefix}comparisons_${etype}`
1823
+ `${this.prefix}comparisons_${etype}`,
1816
1824
  )} ${cTable} ON ${dTable}."guid"=${cTable}."guid" AND ${dTable}."name"=${cTable}."name"
1817
1825
  ${sortJoin}
1818
1826
  INNER JOIN (
1819
1827
  SELECT ${ieTable}."guid"
1820
1828
  FROM ${PostgreSQLDriver.escape(
1821
- `${this.prefix}entities_${etype}`
1829
+ `${this.prefix}entities_${etype}`,
1822
1830
  )} ${ieTable}
1823
1831
  ${sortJoinInner}
1824
1832
  ORDER BY ${sortByInner}${limit}${offset}
@@ -1835,13 +1843,13 @@ export default class PostgreSQLDriver extends NymphDriver {
1835
1843
  ${cTable}."string",
1836
1844
  ${cTable}."number"
1837
1845
  FROM ${PostgreSQLDriver.escape(
1838
- `${this.prefix}entities_${etype}`
1846
+ `${this.prefix}entities_${etype}`,
1839
1847
  )} ${eTable}
1840
1848
  LEFT JOIN ${PostgreSQLDriver.escape(
1841
- `${this.prefix}data_${etype}`
1849
+ `${this.prefix}data_${etype}`,
1842
1850
  )} ${dTable} ON ${eTable}."guid"=${dTable}."guid"
1843
1851
  INNER JOIN ${PostgreSQLDriver.escape(
1844
- `${this.prefix}comparisons_${etype}`
1852
+ `${this.prefix}comparisons_${etype}`,
1845
1853
  )} ${cTable} ON ${dTable}."guid"=${cTable}."guid" AND ${dTable}."name"=${cTable}."name"
1846
1854
  ${sortJoin}
1847
1855
  ORDER BY ${sortBy}, ${eTable}."guid"`;
@@ -1864,17 +1872,17 @@ export default class PostgreSQLDriver extends NymphDriver {
1864
1872
  protected performQuery(
1865
1873
  options: Options,
1866
1874
  formattedSelectors: FormattedSelector[],
1867
- etype: string
1875
+ etype: string,
1868
1876
  ): {
1869
1877
  result: any;
1870
1878
  } {
1871
1879
  const { query, params, etypes } = this.makeEntityQuery(
1872
1880
  options,
1873
1881
  formattedSelectors,
1874
- etype
1882
+ etype,
1875
1883
  );
1876
1884
  const result = this.queryIter(query, { etypes, params }).then((val) =>
1877
- val[Symbol.iterator]()
1885
+ val[Symbol.iterator](),
1878
1886
  );
1879
1887
  return {
1880
1888
  result,
@@ -1923,7 +1931,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1923
1931
  : row.value === 'S'
1924
1932
  ? JSON.stringify(row.string)
1925
1933
  : row.value,
1926
- })
1934
+ }),
1927
1935
  );
1928
1936
 
1929
1937
  const result = await resultPromise;
@@ -1940,13 +1948,13 @@ export default class PostgreSQLDriver extends NymphDriver {
1940
1948
  }
1941
1949
  const result = await this.queryGet(
1942
1950
  `SELECT "cur_uid" FROM ${PostgreSQLDriver.escape(
1943
- `${this.prefix}uids`
1951
+ `${this.prefix}uids`,
1944
1952
  )} WHERE "name"=@name;`,
1945
1953
  {
1946
1954
  params: {
1947
1955
  name: name,
1948
1956
  },
1949
- }
1957
+ },
1950
1958
  );
1951
1959
  return result?.cur_uid == null ? null : Number(result.cur_uid);
1952
1960
  }
@@ -1958,18 +1966,18 @@ export default class PostgreSQLDriver extends NymphDriver {
1958
1966
  async (guid, tags, sdata, etype) => {
1959
1967
  await this.queryRun(
1960
1968
  `DELETE FROM ${PostgreSQLDriver.escape(
1961
- `${this.prefix}entities_${etype}`
1969
+ `${this.prefix}entities_${etype}`,
1962
1970
  )} WHERE "guid"=decode(@guid, 'hex');`,
1963
1971
  {
1964
1972
  etypes: [etype],
1965
1973
  params: {
1966
1974
  guid,
1967
1975
  },
1968
- }
1976
+ },
1969
1977
  );
1970
1978
  await this.queryRun(
1971
1979
  `INSERT INTO ${PostgreSQLDriver.escape(
1972
- `${this.prefix}entities_${etype}`
1980
+ `${this.prefix}entities_${etype}`,
1973
1981
  )} ("guid", "tags", "cdate", "mdate") VALUES (decode(@guid, 'hex'), @tags, @cdate, @mdate);`,
1974
1982
  {
1975
1983
  etypes: [etype],
@@ -1983,47 +1991,47 @@ export default class PostgreSQLDriver extends NymphDriver {
1983
1991
  ? null
1984
1992
  : Number(JSON.parse(sdata.mdate)),
1985
1993
  },
1986
- }
1994
+ },
1987
1995
  );
1988
1996
  const promises = [];
1989
1997
  promises.push(
1990
1998
  this.queryRun(
1991
1999
  `DELETE FROM ${PostgreSQLDriver.escape(
1992
- `${this.prefix}data_${etype}`
2000
+ `${this.prefix}data_${etype}`,
1993
2001
  )} WHERE "guid"=decode(@guid, 'hex');`,
1994
2002
  {
1995
2003
  etypes: [etype],
1996
2004
  params: {
1997
2005
  guid,
1998
2006
  },
1999
- }
2000
- )
2007
+ },
2008
+ ),
2001
2009
  );
2002
2010
  promises.push(
2003
2011
  this.queryRun(
2004
2012
  `DELETE FROM ${PostgreSQLDriver.escape(
2005
- `${this.prefix}comparisons_${etype}`
2013
+ `${this.prefix}comparisons_${etype}`,
2006
2014
  )} WHERE "guid"=decode(@guid, 'hex');`,
2007
2015
  {
2008
2016
  etypes: [etype],
2009
2017
  params: {
2010
2018
  guid,
2011
2019
  },
2012
- }
2013
- )
2020
+ },
2021
+ ),
2014
2022
  );
2015
2023
  promises.push(
2016
2024
  this.queryRun(
2017
2025
  `DELETE FROM ${PostgreSQLDriver.escape(
2018
- `${this.prefix}references_${etype}`
2026
+ `${this.prefix}references_${etype}`,
2019
2027
  )} WHERE "guid"=decode(@guid, 'hex');`,
2020
2028
  {
2021
2029
  etypes: [etype],
2022
2030
  params: {
2023
2031
  guid,
2024
2032
  },
2025
- }
2026
- )
2033
+ },
2034
+ ),
2027
2035
  );
2028
2036
  await Promise.all(promises);
2029
2037
  delete sdata.cdate;
@@ -2044,7 +2052,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2044
2052
  promises.push(
2045
2053
  this.queryRun(
2046
2054
  `INSERT INTO ${PostgreSQLDriver.escape(
2047
- `${this.prefix}data_${etype}`
2055
+ `${this.prefix}data_${etype}`,
2048
2056
  )} ("guid", "name", "value") VALUES (decode(@guid, 'hex'), @name, @storageValue);`,
2049
2057
  {
2050
2058
  etypes: [etype],
@@ -2053,13 +2061,13 @@ export default class PostgreSQLDriver extends NymphDriver {
2053
2061
  name,
2054
2062
  storageValue,
2055
2063
  },
2056
- }
2057
- )
2064
+ },
2065
+ ),
2058
2066
  );
2059
2067
  promises.push(
2060
2068
  this.queryRun(
2061
2069
  `INSERT INTO ${PostgreSQLDriver.escape(
2062
- `${this.prefix}comparisons_${etype}`
2070
+ `${this.prefix}comparisons_${etype}`,
2063
2071
  )} ("guid", "name", "truthy", "string", "number") VALUES (decode(@guid, 'hex'), @name, @truthy, @string, @number);`,
2064
2072
  {
2065
2073
  etypes: [etype],
@@ -2070,15 +2078,15 @@ export default class PostgreSQLDriver extends NymphDriver {
2070
2078
  string: `${uvalue}`,
2071
2079
  number: isNaN(Number(uvalue)) ? null : Number(uvalue),
2072
2080
  },
2073
- }
2074
- )
2081
+ },
2082
+ ),
2075
2083
  );
2076
2084
  const references = this.findReferences(value);
2077
2085
  for (const reference of references) {
2078
2086
  promises.push(
2079
2087
  this.queryRun(
2080
2088
  `INSERT INTO ${PostgreSQLDriver.escape(
2081
- `${this.prefix}references_${etype}`
2089
+ `${this.prefix}references_${etype}`,
2082
2090
  )} ("guid", "name", "reference") VALUES (decode(@guid, 'hex'), @name, decode(@reference, 'hex'));`,
2083
2091
  {
2084
2092
  etypes: [etype],
@@ -2087,8 +2095,8 @@ export default class PostgreSQLDriver extends NymphDriver {
2087
2095
  name,
2088
2096
  reference,
2089
2097
  },
2090
- }
2091
- )
2098
+ },
2099
+ ),
2092
2100
  );
2093
2101
  }
2094
2102
  }
@@ -2097,24 +2105,24 @@ export default class PostgreSQLDriver extends NymphDriver {
2097
2105
  async (name, curUid) => {
2098
2106
  await this.queryRun(
2099
2107
  `DELETE FROM ${PostgreSQLDriver.escape(
2100
- `${this.prefix}uids`
2108
+ `${this.prefix}uids`,
2101
2109
  )} WHERE "name"=@name;`,
2102
2110
  {
2103
2111
  params: {
2104
2112
  name,
2105
2113
  },
2106
- }
2114
+ },
2107
2115
  );
2108
2116
  await this.queryRun(
2109
2117
  `INSERT INTO ${PostgreSQLDriver.escape(
2110
- `${this.prefix}uids`
2118
+ `${this.prefix}uids`,
2111
2119
  )} ("name", "cur_uid") VALUES (@name, @curUid);`,
2112
2120
  {
2113
2121
  params: {
2114
2122
  name,
2115
2123
  curUid,
2116
2124
  },
2117
- }
2125
+ },
2118
2126
  );
2119
2127
  },
2120
2128
  async () => {
@@ -2122,7 +2130,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2122
2130
  },
2123
2131
  async () => {
2124
2132
  await this.commit('nymph-import');
2125
- }
2133
+ },
2126
2134
  );
2127
2135
 
2128
2136
  return result;
@@ -2140,13 +2148,13 @@ export default class PostgreSQLDriver extends NymphDriver {
2140
2148
  try {
2141
2149
  const lock = await this.queryGet(
2142
2150
  `SELECT "cur_uid" FROM ${PostgreSQLDriver.escape(
2143
- `${this.prefix}uids`
2151
+ `${this.prefix}uids`,
2144
2152
  )} WHERE "name"=@name FOR UPDATE;`,
2145
2153
  {
2146
2154
  params: {
2147
2155
  name,
2148
2156
  },
2149
- }
2157
+ },
2150
2158
  );
2151
2159
  let curUid: number | undefined =
2152
2160
  lock?.cur_uid == null ? undefined : Number(lock.cur_uid);
@@ -2154,27 +2162,27 @@ export default class PostgreSQLDriver extends NymphDriver {
2154
2162
  curUid = 1;
2155
2163
  await this.queryRun(
2156
2164
  `INSERT INTO ${PostgreSQLDriver.escape(
2157
- `${this.prefix}uids`
2165
+ `${this.prefix}uids`,
2158
2166
  )} ("name", "cur_uid") VALUES (@name, @curUid);`,
2159
2167
  {
2160
2168
  params: {
2161
2169
  name,
2162
2170
  curUid,
2163
2171
  },
2164
- }
2172
+ },
2165
2173
  );
2166
2174
  } else {
2167
2175
  curUid++;
2168
2176
  await this.queryRun(
2169
2177
  `UPDATE ${PostgreSQLDriver.escape(
2170
- `${this.prefix}uids`
2178
+ `${this.prefix}uids`,
2171
2179
  )} SET "cur_uid"=@curUid WHERE "name"=@name;`,
2172
2180
  {
2173
2181
  params: {
2174
2182
  name,
2175
2183
  curUid,
2176
2184
  },
2177
- }
2185
+ },
2178
2186
  );
2179
2187
  }
2180
2188
  await this.commit('nymph-newuid');
@@ -2191,14 +2199,14 @@ export default class PostgreSQLDriver extends NymphDriver {
2191
2199
  }
2192
2200
  await this.queryRun(
2193
2201
  `UPDATE ${PostgreSQLDriver.escape(
2194
- `${this.prefix}uids`
2202
+ `${this.prefix}uids`,
2195
2203
  )} SET "name"=@newName WHERE "name"=@oldName;`,
2196
2204
  {
2197
2205
  params: {
2198
2206
  newName,
2199
2207
  oldName,
2200
2208
  },
2201
- }
2209
+ },
2202
2210
  );
2203
2211
  return true;
2204
2212
  }
@@ -2206,7 +2214,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2206
2214
  public async rollback(name: string) {
2207
2215
  if (name == null || typeof name !== 'string' || name.length === 0) {
2208
2216
  throw new InvalidParametersError(
2209
- 'Transaction rollback attempted without a name.'
2217
+ 'Transaction rollback attempted without a name.',
2210
2218
  );
2211
2219
  }
2212
2220
  if (!this.transaction || this.transaction.count === 0) {
@@ -2214,7 +2222,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2214
2222
  return true;
2215
2223
  }
2216
2224
  await this.queryRun(
2217
- `ROLLBACK TO SAVEPOINT ${PostgreSQLDriver.escape(name)};`
2225
+ `ROLLBACK TO SAVEPOINT ${PostgreSQLDriver.escape(name)};`,
2218
2226
  );
2219
2227
  this.transaction.count--;
2220
2228
  if (this.transaction.count === 0) {
@@ -2231,12 +2239,12 @@ export default class PostgreSQLDriver extends NymphDriver {
2231
2239
  guid: string,
2232
2240
  data: EntityData,
2233
2241
  sdata: SerializedEntityData,
2234
- etype: string
2242
+ etype: string,
2235
2243
  ) => {
2236
2244
  const runInsertQuery = async (
2237
2245
  name: string,
2238
2246
  value: any,
2239
- svalue: string
2247
+ svalue: string,
2240
2248
  ) => {
2241
2249
  if (value === undefined) {
2242
2250
  return;
@@ -2251,7 +2259,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2251
2259
  promises.push(
2252
2260
  this.queryRun(
2253
2261
  `INSERT INTO ${PostgreSQLDriver.escape(
2254
- `${this.prefix}data_${etype}`
2262
+ `${this.prefix}data_${etype}`,
2255
2263
  )} ("guid", "name", "value") VALUES (decode(@guid, 'hex'), @name, @storageValue);`,
2256
2264
  {
2257
2265
  etypes: [etype],
@@ -2260,13 +2268,13 @@ export default class PostgreSQLDriver extends NymphDriver {
2260
2268
  name,
2261
2269
  storageValue,
2262
2270
  },
2263
- }
2264
- )
2271
+ },
2272
+ ),
2265
2273
  );
2266
2274
  promises.push(
2267
2275
  this.queryRun(
2268
2276
  `INSERT INTO ${PostgreSQLDriver.escape(
2269
- `${this.prefix}comparisons_${etype}`
2277
+ `${this.prefix}comparisons_${etype}`,
2270
2278
  )} ("guid", "name", "truthy", "string", "number") VALUES (decode(@guid, 'hex'), @name, @truthy, @string, @number);`,
2271
2279
  {
2272
2280
  etypes: [etype],
@@ -2277,15 +2285,15 @@ export default class PostgreSQLDriver extends NymphDriver {
2277
2285
  string: `${value}`,
2278
2286
  number: isNaN(Number(value)) ? null : Number(value),
2279
2287
  },
2280
- }
2281
- )
2288
+ },
2289
+ ),
2282
2290
  );
2283
2291
  const references = this.findReferences(svalue);
2284
2292
  for (const reference of references) {
2285
2293
  promises.push(
2286
2294
  this.queryRun(
2287
2295
  `INSERT INTO ${PostgreSQLDriver.escape(
2288
- `${this.prefix}references_${etype}`
2296
+ `${this.prefix}references_${etype}`,
2289
2297
  )} ("guid", "name", "reference") VALUES (decode(@guid, 'hex'), @name, decode(@reference, 'hex'));`,
2290
2298
  {
2291
2299
  etypes: [etype],
@@ -2294,8 +2302,8 @@ export default class PostgreSQLDriver extends NymphDriver {
2294
2302
  name,
2295
2303
  reference,
2296
2304
  },
2297
- }
2298
- )
2305
+ },
2306
+ ),
2299
2307
  );
2300
2308
  }
2301
2309
  await Promise.all(promises);
@@ -2319,7 +2327,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2319
2327
  }
2320
2328
  await this.queryRun(
2321
2329
  `INSERT INTO ${PostgreSQLDriver.escape(
2322
- `${this.prefix}entities_${etype}`
2330
+ `${this.prefix}entities_${etype}`,
2323
2331
  )} ("guid", "tags", "cdate", "mdate") VALUES (decode(@guid, 'hex'), @tags, @cdate, @cdate);`,
2324
2332
  {
2325
2333
  etypes: [etype],
@@ -2328,7 +2336,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2328
2336
  tags,
2329
2337
  cdate,
2330
2338
  },
2331
- }
2339
+ },
2332
2340
  );
2333
2341
  await insertData(guid, data, sdata, etype);
2334
2342
  return true;
@@ -2344,59 +2352,59 @@ export default class PostgreSQLDriver extends NymphDriver {
2344
2352
  promises.push(
2345
2353
  this.queryRun(
2346
2354
  `SELECT 1 FROM ${PostgreSQLDriver.escape(
2347
- `${this.prefix}entities_${etype}`
2355
+ `${this.prefix}entities_${etype}`,
2348
2356
  )} WHERE "guid"=decode(@guid, 'hex') FOR UPDATE;`,
2349
2357
  {
2350
2358
  etypes: [etype],
2351
2359
  params: {
2352
2360
  guid,
2353
2361
  },
2354
- }
2355
- )
2362
+ },
2363
+ ),
2356
2364
  );
2357
2365
  promises.push(
2358
2366
  this.queryRun(
2359
2367
  `SELECT 1 FROM ${PostgreSQLDriver.escape(
2360
- `${this.prefix}data_${etype}`
2368
+ `${this.prefix}data_${etype}`,
2361
2369
  )} WHERE "guid"=decode(@guid, 'hex') FOR UPDATE;`,
2362
2370
  {
2363
2371
  etypes: [etype],
2364
2372
  params: {
2365
2373
  guid,
2366
2374
  },
2367
- }
2368
- )
2375
+ },
2376
+ ),
2369
2377
  );
2370
2378
  promises.push(
2371
2379
  this.queryRun(
2372
2380
  `SELECT 1 FROM ${PostgreSQLDriver.escape(
2373
- `${this.prefix}comparisons_${etype}`
2381
+ `${this.prefix}comparisons_${etype}`,
2374
2382
  )} WHERE "guid"=decode(@guid, 'hex') FOR UPDATE;`,
2375
2383
  {
2376
2384
  etypes: [etype],
2377
2385
  params: {
2378
2386
  guid,
2379
2387
  },
2380
- }
2381
- )
2388
+ },
2389
+ ),
2382
2390
  );
2383
2391
  promises.push(
2384
2392
  this.queryRun(
2385
2393
  `SELECT 1 FROM ${PostgreSQLDriver.escape(
2386
- `${this.prefix}references_${etype}`
2394
+ `${this.prefix}references_${etype}`,
2387
2395
  )} WHERE "guid"=decode(@guid, 'hex') FOR UPDATE;`,
2388
2396
  {
2389
2397
  etypes: [etype],
2390
2398
  params: {
2391
2399
  guid,
2392
2400
  },
2393
- }
2394
- )
2401
+ },
2402
+ ),
2395
2403
  );
2396
2404
  await Promise.all(promises);
2397
2405
  const info = await this.queryRun(
2398
2406
  `UPDATE ${PostgreSQLDriver.escape(
2399
- `${this.prefix}entities_${etype}`
2407
+ `${this.prefix}entities_${etype}`,
2400
2408
  )} SET "tags"=@tags, "mdate"=@mdate WHERE "guid"=decode(@guid, 'hex') AND "mdate" <= @emdate;`,
2401
2409
  {
2402
2410
  etypes: [etype],
@@ -2406,7 +2414,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2406
2414
  guid,
2407
2415
  emdate: isNaN(Number(entity.mdate)) ? 0 : Number(entity.mdate),
2408
2416
  },
2409
- }
2417
+ },
2410
2418
  );
2411
2419
  let success = false;
2412
2420
  if (info.rowCount === 1) {
@@ -2414,41 +2422,41 @@ export default class PostgreSQLDriver extends NymphDriver {
2414
2422
  promises.push(
2415
2423
  this.queryRun(
2416
2424
  `DELETE FROM ${PostgreSQLDriver.escape(
2417
- `${this.prefix}data_${etype}`
2425
+ `${this.prefix}data_${etype}`,
2418
2426
  )} WHERE "guid"=decode(@guid, 'hex');`,
2419
2427
  {
2420
2428
  etypes: [etype],
2421
2429
  params: {
2422
2430
  guid,
2423
2431
  },
2424
- }
2425
- )
2432
+ },
2433
+ ),
2426
2434
  );
2427
2435
  promises.push(
2428
2436
  this.queryRun(
2429
2437
  `DELETE FROM ${PostgreSQLDriver.escape(
2430
- `${this.prefix}comparisons_${etype}`
2438
+ `${this.prefix}comparisons_${etype}`,
2431
2439
  )} WHERE "guid"=decode(@guid, 'hex');`,
2432
2440
  {
2433
2441
  etypes: [etype],
2434
2442
  params: {
2435
2443
  guid,
2436
2444
  },
2437
- }
2438
- )
2445
+ },
2446
+ ),
2439
2447
  );
2440
2448
  promises.push(
2441
2449
  this.queryRun(
2442
2450
  `DELETE FROM ${PostgreSQLDriver.escape(
2443
- `${this.prefix}references_${etype}`
2451
+ `${this.prefix}references_${etype}`,
2444
2452
  )} WHERE "guid"=decode(@guid, 'hex');`,
2445
2453
  {
2446
2454
  etypes: [etype],
2447
2455
  params: {
2448
2456
  guid,
2449
2457
  },
2450
- }
2451
- )
2458
+ },
2459
+ ),
2452
2460
  );
2453
2461
  await Promise.all(promises);
2454
2462
  await insertData(guid, data, sdata, etype);
@@ -2466,7 +2474,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2466
2474
  await this.rollback('nymph-save');
2467
2475
  }
2468
2476
  return success;
2469
- }
2477
+ },
2470
2478
  );
2471
2479
 
2472
2480
  return result;
@@ -2484,25 +2492,25 @@ export default class PostgreSQLDriver extends NymphDriver {
2484
2492
  try {
2485
2493
  await this.queryRun(
2486
2494
  `DELETE FROM ${PostgreSQLDriver.escape(
2487
- `${this.prefix}uids`
2495
+ `${this.prefix}uids`,
2488
2496
  )} WHERE "name"=@name;`,
2489
2497
  {
2490
2498
  params: {
2491
2499
  name,
2492
2500
  curUid,
2493
2501
  },
2494
- }
2502
+ },
2495
2503
  );
2496
2504
  await this.queryRun(
2497
2505
  `INSERT INTO ${PostgreSQLDriver.escape(
2498
- `${this.prefix}uids`
2506
+ `${this.prefix}uids`,
2499
2507
  )} ("name", "cur_uid") VALUES (@name, @curUid);`,
2500
2508
  {
2501
2509
  params: {
2502
2510
  name,
2503
2511
  curUid,
2504
2512
  },
2505
- }
2513
+ },
2506
2514
  );
2507
2515
  await this.commit('nymph-setuid');
2508
2516
  return true;
@@ -2515,7 +2523,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2515
2523
  private async internalTransaction(name: string) {
2516
2524
  if (name == null || typeof name !== 'string' || name.length === 0) {
2517
2525
  throw new InvalidParametersError(
2518
- 'Transaction start attempted without a name.'
2526
+ 'Transaction start attempted without a name.',
2519
2527
  );
2520
2528
  }
2521
2529
 
@@ -2537,7 +2545,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2537
2545
  }
2538
2546
 
2539
2547
  public async startTransaction(name: string) {
2540
- const inTransaction = this.inTransaction();
2548
+ const inTransaction = await this.inTransaction();
2541
2549
  const transaction = await this.internalTransaction(name);
2542
2550
  if (!inTransaction) {
2543
2551
  this.transaction = null;