@cap-js/postgres 1.5.0 → 1.5.1
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 +7 -0
- package/lib/PostgresService.js +40 -14
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
- The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
5
5
|
- This project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.5.1](https://github.com/cap-js/cds-dbs/compare/postgres-v1.5.0...postgres-v1.5.1) (2024-02-16)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
* **`sqlite`:** Retain Error object for unique constraint violation ([#446](https://github.com/cap-js/cds-dbs/issues/446)) ([d27ee79](https://github.com/cap-js/cds-dbs/commit/d27ee79b4c4eea8522bf5dd2a288638f54029567))
|
|
13
|
+
|
|
7
14
|
## [1.5.0](https://github.com/cap-js/cds-dbs/compare/postgres-v1.4.1...postgres-v1.5.0) (2024-02-02)
|
|
8
15
|
|
|
9
16
|
|
package/lib/PostgresService.js
CHANGED
|
@@ -308,14 +308,30 @@ GROUP BY k
|
|
|
308
308
|
return super.onSELECT({ query, data })
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
+
async onINSERT(req) {
|
|
312
|
+
try {
|
|
313
|
+
return await super.onINSERT(req)
|
|
314
|
+
} catch (err) {
|
|
315
|
+
throw _not_unique(err, 'ENTITY_ALREADY_EXISTS')
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async onUPDATE(req) {
|
|
320
|
+
try {
|
|
321
|
+
return await super.onUPDATE(req)
|
|
322
|
+
} catch (err) {
|
|
323
|
+
throw _not_unique(err, 'UNIQUE_CONSTRAINT_VIOLATION')
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
311
327
|
static CQN2SQL = class CQN2Postgres extends SQLService.CQN2SQL {
|
|
312
328
|
_orderBy(orderBy, localized, locale) {
|
|
313
329
|
return orderBy.map(
|
|
314
330
|
localized
|
|
315
331
|
? c =>
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
332
|
+
this.expr(c) +
|
|
333
|
+
(c.element?.[this.class._localized] ? ` COLLATE "${locale}"` : '') +
|
|
334
|
+
(c.sort === 'desc' || c.sort === -1 ? ' DESC' : ' ASC')
|
|
319
335
|
: c => this.expr(c) + (c.sort === 'desc' || c.sort === -1 ? ' DESC' : ' ASC'),
|
|
320
336
|
)
|
|
321
337
|
}
|
|
@@ -365,9 +381,8 @@ GROUP BY k
|
|
|
365
381
|
})
|
|
366
382
|
// REVISIT: Remove SELECT ${cols} by adjusting SELECT_columns
|
|
367
383
|
let obj = `to_jsonb(${queryAlias}.*)`
|
|
368
|
-
return `SELECT ${
|
|
369
|
-
|
|
370
|
-
} as _json_ FROM (SELECT ${cols} FROM (${sql}) as ${queryAlias}) as ${queryAlias}`
|
|
384
|
+
return `SELECT ${SELECT.one || SELECT.expand === 'root' ? obj : `coalesce(jsonb_agg (${obj}),'[]'::jsonb)`
|
|
385
|
+
} as _json_ FROM (SELECT ${cols} FROM (${sql}) as ${queryAlias}) as ${queryAlias}`
|
|
371
386
|
}
|
|
372
387
|
|
|
373
388
|
doubleQuote(name) {
|
|
@@ -455,6 +470,7 @@ GROUP BY k
|
|
|
455
470
|
Timestamp: e => `to_char(${e}, 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')`,
|
|
456
471
|
UTCDateTime: e => `to_char(${e}, 'YYYY-MM-DD"T"HH24:MI:SS"Z"')`,
|
|
457
472
|
UTCTimestamp: e => `to_char(${e}, 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')`,
|
|
473
|
+
Association: e => `jsonb(${e})`,
|
|
458
474
|
struct: e => `jsonb(${e})`,
|
|
459
475
|
array: e => `jsonb(${e})`,
|
|
460
476
|
}
|
|
@@ -551,14 +567,14 @@ class QueryStream extends Query {
|
|
|
551
567
|
this.stream = new Readable({
|
|
552
568
|
read: this.rows
|
|
553
569
|
? () => {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
570
|
+
this.stream.pause()
|
|
571
|
+
// Request more rows
|
|
572
|
+
this.connection.execute({
|
|
573
|
+
portal: this.portal,
|
|
574
|
+
rows: this.rows,
|
|
575
|
+
})
|
|
576
|
+
this.connection.flush()
|
|
577
|
+
}
|
|
562
578
|
: () => {},
|
|
563
579
|
})
|
|
564
580
|
this.push = this.stream.push.bind(this.stream)
|
|
@@ -739,4 +755,14 @@ class ParameterStream extends Writable {
|
|
|
739
755
|
}
|
|
740
756
|
}
|
|
741
757
|
|
|
758
|
+
function _not_unique(err, code) {
|
|
759
|
+
if (err.code === '23505')
|
|
760
|
+
return Object.assign(err, {
|
|
761
|
+
originalMessage: err.message, // FIXME: required because of next line
|
|
762
|
+
message: code, // FIXME: misusing message as code
|
|
763
|
+
code: 400, // FIXME: misusing code as (http) status
|
|
764
|
+
})
|
|
765
|
+
return err
|
|
766
|
+
}
|
|
767
|
+
|
|
742
768
|
module.exports = PostgresService
|
package/package.json
CHANGED