@cap-js/postgres 1.10.1 → 1.10.3
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 +14 -0
- package/lib/PostgresService.js +49 -23
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@
|
|
|
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.10.3](https://github.com/cap-js/cds-dbs/compare/postgres-v1.10.2...postgres-v1.10.3) (2024-10-30)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
* increase min version cap-js/db-service ([#876](https://github.com/cap-js/cds-dbs/issues/876)) ([e20eef8](https://github.com/cap-js/cds-dbs/commit/e20eef83f3ef0e1595932e31885096ca566cb153))
|
|
13
|
+
|
|
14
|
+
## [1.10.2](https://github.com/cap-js/cds-dbs/compare/postgres-v1.10.1...postgres-v1.10.2) (2024-10-28)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
* properly support `default`, `cds.on.insert` and `cds.on.update` for `UPSERT` queries ([#425](https://github.com/cap-js/cds-dbs/issues/425)) ([338e9f5](https://github.com/cap-js/cds-dbs/commit/338e9f5de9109d36013208547fc648c17ce8c7b0))
|
|
20
|
+
|
|
7
21
|
## [1.10.1](https://github.com/cap-js/cds-dbs/compare/postgres-v1.10.0...postgres-v1.10.1) (2024-10-15)
|
|
8
22
|
|
|
9
23
|
|
package/lib/PostgresService.js
CHANGED
|
@@ -424,11 +424,32 @@ GROUP BY k
|
|
|
424
424
|
|
|
425
425
|
// REVISIT: this should probably be made a bit easier to adopt
|
|
426
426
|
return (this.sql = this.sql
|
|
427
|
-
// Adjusts json path expressions to be postgres specific
|
|
428
|
-
.replace(/->>'\$(?:(?:\."(.*?)")|(?:\[(\d*)\]))'/g, (a, b, c) => (b ? `->>'${b}'` : `->>${c}`))
|
|
429
427
|
// Adjusts json function to be postgres specific
|
|
430
428
|
.replace('json_each(?)', 'json_array_elements($1::json)')
|
|
431
|
-
|
|
429
|
+
)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
UPSERT(q, isUpsert = false) {
|
|
433
|
+
super.UPSERT(q, isUpsert)
|
|
434
|
+
|
|
435
|
+
// REVISIT: this should probably be made a bit easier to adopt
|
|
436
|
+
return (this.sql = this.sql
|
|
437
|
+
// Adjusts json function to be postgres specific
|
|
438
|
+
.replace('json_each(?)', 'json_array_elements($1::json)')
|
|
439
|
+
)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
managed_extract(name, element, converter) {
|
|
443
|
+
const { UPSERT, INSERT } = this.cqn
|
|
444
|
+
const extract = !(INSERT?.entries || UPSERT?.entries) && (INSERT?.rows || UPSERT?.rows)
|
|
445
|
+
? `value->>${this.columns.indexOf(name)}`
|
|
446
|
+
: `value->>'${name.replace(/'/g, "''")}'`
|
|
447
|
+
const sql = converter?.(extract) || extract
|
|
448
|
+
return { extract, sql }
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
managed_default(name, managed, src) {
|
|
452
|
+
return `(CASE WHEN json_typeof(value->${this.managed_extract(name).extract.slice(8)}) IS NULL THEN ${managed} ELSE ${src} END)`
|
|
432
453
|
}
|
|
433
454
|
|
|
434
455
|
param({ ref }) {
|
|
@@ -503,27 +524,31 @@ GROUP BY k
|
|
|
503
524
|
// Used for INSERT statements
|
|
504
525
|
static InputConverters = {
|
|
505
526
|
...super.InputConverters,
|
|
506
|
-
// UUID:
|
|
507
|
-
boolean: e => `CASE ${e} WHEN 'true' THEN true WHEN 'false' THEN false END`,
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
527
|
+
// UUID: (e) => e[0] === '$' ? e : `CAST(${e} as UUID)`, // UUID is strict in formatting sflight does not comply
|
|
528
|
+
boolean: e => e[0] === '$' ? e : `CASE ${e} WHEN 'true' THEN true WHEN 'false' THEN false END`,
|
|
529
|
+
// REVISIT: Postgres and HANA round Decimal numbers differently therefore precision and scale are removed
|
|
530
|
+
// Float: (e, t) => e[0] === '$' ? e : `CAST(${e} as decimal${t.precision && t.scale ? `(${t.precision},${t.scale})` : ''})`,
|
|
531
|
+
// Decimal: (e, t) => e[0] === '$' ? e : `CAST(${e} as decimal${t.precision && t.scale ? `(${t.precision},${t.scale})` : ''})`,
|
|
532
|
+
Float: e => e[0] === '$' ? e : `CAST(${e} as decimal)`,
|
|
533
|
+
Decimal: e => e[0] === '$' ? e : `CAST(${e} as decimal)`,
|
|
534
|
+
Integer: e => e[0] === '$' ? e : `CAST(${e} as integer)`,
|
|
535
|
+
Int64: e => e[0] === '$' ? e : `CAST(${e} as bigint)`,
|
|
536
|
+
Date: e => e[0] === '$' ? e : `CAST(${e} as DATE)`,
|
|
537
|
+
Time: e => e[0] === '$' ? e : `CAST(${e} as TIME)`,
|
|
538
|
+
DateTime: e => e[0] === '$' ? e : `CAST(${e} as TIMESTAMP)`,
|
|
539
|
+
Timestamp: e => e[0] === '$' ? e : `CAST(${e} as TIMESTAMP)`,
|
|
516
540
|
// REVISIT: Remove that with upcomming fixes in cds.linked
|
|
517
|
-
Double: (e, t) => `CAST(${e} as decimal${t.precision && t.scale ? `(${t.precision},${t.scale})` : ''})`,
|
|
518
|
-
DecimalFloat: (e, t) => `CAST(${e} as decimal${t.precision && t.scale ? `(${t.precision},${t.scale})` : ''})`,
|
|
519
|
-
Binary: e => `DECODE(${e},'base64')`,
|
|
520
|
-
LargeBinary: e => `DECODE(${e},'base64')`,
|
|
541
|
+
Double: (e, t) => e[0] === '$' ? e : `CAST(${e} as decimal${t.precision && t.scale ? `(${t.precision},${t.scale})` : ''})`,
|
|
542
|
+
DecimalFloat: (e, t) => e[0] === '$' ? e : `CAST(${e} as decimal${t.precision && t.scale ? `(${t.precision},${t.scale})` : ''})`,
|
|
543
|
+
Binary: e => e[0] === '$' ? e : `DECODE(${e},'base64')`,
|
|
544
|
+
LargeBinary: e => e[0] === '$' ? e : `DECODE(${e},'base64')`,
|
|
521
545
|
|
|
522
546
|
// HANA Types
|
|
523
|
-
'cds.hana.CLOB': e => `DECODE(${e},'base64')`,
|
|
524
|
-
'cds.hana.BINARY': e => `DECODE(${e},'base64')`,
|
|
525
|
-
|
|
526
|
-
'cds.hana.
|
|
547
|
+
'cds.hana.CLOB': e => e[0] === '$' ? e : `DECODE(${e},'base64')`,
|
|
548
|
+
'cds.hana.BINARY': e => e[0] === '$' ? e : `DECODE(${e},'base64')`,
|
|
549
|
+
// REVISIT: have someone take a look at how this syntax exactly works in postgres with postgis
|
|
550
|
+
'cds.hana.ST_POINT': e => `(${e})::point`,
|
|
551
|
+
'cds.hana.ST_GEOMETRY': e => `(${e})::polygon`,
|
|
527
552
|
}
|
|
528
553
|
|
|
529
554
|
static OutputConverters = {
|
|
@@ -548,8 +573,9 @@ GROUP BY k
|
|
|
548
573
|
: `cast(${expr} as varchar)`
|
|
549
574
|
: undefined,
|
|
550
575
|
|
|
551
|
-
// Convert
|
|
552
|
-
'cds.hana.ST_POINT': expr => `
|
|
576
|
+
// Convert ST types back to WKT format
|
|
577
|
+
'cds.hana.ST_POINT': expr => `ST_AsText(${expr})`,
|
|
578
|
+
'cds.hana.ST_POINT': expr => `ST_AsText(${expr})`,
|
|
553
579
|
}
|
|
554
580
|
}
|
|
555
581
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/postgres",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.3",
|
|
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": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"start": "docker compose -f pg-stack.yml up -d"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@cap-js/db-service": "^1.
|
|
30
|
+
"@cap-js/db-service": "^1.14.1",
|
|
31
31
|
"pg": "^8"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|