@cap-js/postgres 1.14.0 → 2.0.0
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 +21 -0
- package/lib/PostgresService.js +38 -26
- package/lib/cql-functions.js +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,27 @@
|
|
|
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
|
+
## [2.0.0](https://github.com/cap-js/cds-dbs/compare/postgres-v1.14.0...postgres-v2.0.0) (2025-05-07)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
|
|
12
|
+
* update peer dependency to @sap/cds@9 ([#1178](https://github.com/cap-js/cds-dbs/issues/1178))
|
|
13
|
+
* update dependency to @cap-js/db-service@2 ([#1178](https://github.com/cap-js/cds-dbs/issues/1178))
|
|
14
|
+
* Unfiltered db constraint errors ([#1165](https://github.com/cap-js/cds-dbs/issues/1165))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
* Support for hierarchical queries ([#1093](https://github.com/cap-js/cds-dbs/issues/1093)) ([246e0b3](https://github.com/cap-js/cds-dbs/commit/246e0b38840f7e132ea49cae335b6be7a55354b3))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
* Unfiltered db constraint errors ([#1165](https://github.com/cap-js/cds-dbs/issues/1165)) ([ff39e22](https://github.com/cap-js/cds-dbs/commit/ff39e22ac6cd3f20c98bc31c1a6bb828aa009796))
|
|
25
|
+
* update peer dependency to @sap/cds@9 ([#1178](https://github.com/cap-js/cds-dbs/issues/1178)) ([#1178](https://github.com/cap-js/cds-dbs/issues/1178)) ([0507edd](https://github.com/cap-js/cds-dbs/commit/0507edd4e1dcb98983b1fb65ade1344d978b7524))
|
|
26
|
+
* update dependency to @cap-js/db-service@2 ([#1178](https://github.com/cap-js/cds-dbs/issues/1178)) ([#1178](https://github.com/cap-js/cds-dbs/issues/1178)) ([0507edd](https://github.com/cap-js/cds-dbs/commit/0507edd4e1dcb98983b1fb65ade1344d978b7524))
|
|
27
|
+
|
|
7
28
|
## [1.14.0](https://github.com/cap-js/cds-dbs/compare/postgres-v1.13.0...postgres-v1.14.0) (2025-04-17)
|
|
8
29
|
|
|
9
30
|
|
package/lib/PostgresService.js
CHANGED
|
@@ -4,7 +4,6 @@ const cds = require('@sap/cds')
|
|
|
4
4
|
const crypto = require('crypto')
|
|
5
5
|
const { Writable, Readable } = require('stream')
|
|
6
6
|
const sessionVariableMap = require('./session.json')
|
|
7
|
-
const SANITIZE_VALUES = process.env.NODE_ENV === 'production' && cds.env.log.sanitize_values !== false
|
|
8
7
|
|
|
9
8
|
class PostgresService extends SQLService {
|
|
10
9
|
init() {
|
|
@@ -327,23 +326,47 @@ GROUP BY k
|
|
|
327
326
|
return super.onSELECT(req)
|
|
328
327
|
}
|
|
329
328
|
|
|
330
|
-
async onINSERT(req) {
|
|
331
|
-
try {
|
|
332
|
-
return await super.onINSERT(req)
|
|
333
|
-
} catch (err) {
|
|
334
|
-
throw _not_unique(err, 'ENTITY_ALREADY_EXISTS', req.data)
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
329
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
330
|
+
static CQN2SQL = class CQN2Postgres extends SQLService.CQN2SQL {
|
|
331
|
+
|
|
332
|
+
render_with() {
|
|
333
|
+
const sql = this.sql
|
|
334
|
+
let recursive = false
|
|
335
|
+
const prefix = this._with.map(q => {
|
|
336
|
+
let sql
|
|
337
|
+
if ('SELECT' in q) sql = `${this.quote(q.as)} AS (${this.SELECT(q)})`
|
|
338
|
+
else if ('SET' in q) {
|
|
339
|
+
recursive = true
|
|
340
|
+
const { SET } = q
|
|
341
|
+
const isDepthFirst = SET.orderBy?.length && (SET.orderBy[0].sort?.toLowerCase() === 'desc' || SET.orderBy[0].sort === -1)
|
|
342
|
+
let alias = q.as
|
|
343
|
+
if (isDepthFirst) {
|
|
344
|
+
alias = alias + '_depth_first'
|
|
345
|
+
SET.args[1].SELECT.from.args.forEach(r => { if (r.ref[0] === q.as) r.ref[0] = alias })
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
sql = `${this.quote(alias)}(${SET.args[0].SELECT.columns?.map(c => this.quote(this.column_name(c))) || ''}) AS (${
|
|
349
|
+
// Root select
|
|
350
|
+
this.SELECT(SET.args[0])} ${
|
|
351
|
+
// Union clause
|
|
352
|
+
SET.op?.toUpperCase() || 'UNION'} ${SET.all ? 'ALL' : ''} ${
|
|
353
|
+
// Repeated join query
|
|
354
|
+
this.SELECT(SET.args[1])
|
|
355
|
+
})${
|
|
356
|
+
// Leverage Postgres specific depth first syntax
|
|
357
|
+
SET.orderBy?.length
|
|
358
|
+
? ` SEARCH DEPTH FIRST BY ${SET.orderBy.map(r => this.ref(r))} SET "$DEPTH$"`
|
|
359
|
+
: ''
|
|
360
|
+
}`
|
|
361
|
+
|
|
362
|
+
// Enforce depth sorting for consuming queries
|
|
363
|
+
if (isDepthFirst) sql += `,${this.quote(q.as)} AS (SELECT * FROM ${this.quote(q.as + '_depth_first')} ORDER BY "$DEPTH$")`
|
|
364
|
+
}
|
|
365
|
+
return { sql }
|
|
366
|
+
})
|
|
367
|
+
this.sql = `WITH${recursive ? ' RECURSIVE' : ''} ${prefix.map(p => p.sql)} ${sql}`
|
|
343
368
|
}
|
|
344
|
-
}
|
|
345
369
|
|
|
346
|
-
static CQN2SQL = class CQN2Postgres extends SQLService.CQN2SQL {
|
|
347
370
|
_orderBy(orderBy, localized, locale) {
|
|
348
371
|
return orderBy.map(c => {
|
|
349
372
|
const nulls = c.nulls || (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? 'LAST' : 'FIRST')
|
|
@@ -877,15 +900,4 @@ class ParameterStream extends Writable {
|
|
|
877
900
|
}
|
|
878
901
|
}
|
|
879
902
|
|
|
880
|
-
function _not_unique(err, code, data) {
|
|
881
|
-
if (err.code === '23505')
|
|
882
|
-
return Object.assign(err, {
|
|
883
|
-
originalMessage: err.message, // FIXME: required because of next line
|
|
884
|
-
message: code, // FIXME: misusing message as code
|
|
885
|
-
code: 400, // FIXME: misusing code as (http) status
|
|
886
|
-
})
|
|
887
|
-
if (data) err.values = SANITIZE_VALUES ? ['***'] : data
|
|
888
|
-
return err
|
|
889
|
-
}
|
|
890
|
-
|
|
891
903
|
module.exports = PostgresService
|
package/lib/cql-functions.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/postgres",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "CDS database service for Postgres",
|
|
5
5
|
"homepage": "https://github.com/cap-js/cds-dbs/tree/main/postgres#cds-database-service-for-postgres",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/cap-js/cds-dbs"
|
|
8
|
+
"url": "git+https://github.com/cap-js/cds-dbs.git"
|
|
9
9
|
},
|
|
10
10
|
"bugs": {
|
|
11
11
|
"url": "https://github.com/cap-js/cds-dbs/issues"
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"start": "docker compose -f pg-stack.yml up -d"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@cap-js/db-service": "^
|
|
30
|
+
"@cap-js/db-service": "^2",
|
|
31
31
|
"pg": "^8"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@sap/cds": ">=
|
|
35
|
-
"@sap/cds-dk": ">=
|
|
34
|
+
"@sap/cds": ">=9",
|
|
35
|
+
"@sap/cds-dk": ">=9"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@sap/cds-dk": {
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
"license": "
|
|
79
|
+
"license": "Apache-2.0"
|
|
80
80
|
}
|