@cap-js/postgres 2.0.1 → 2.0.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/cds-plugin.js +33 -17
- package/lib/PostgresService.js +14 -7
- package/package.json +1 -1
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
|
+
## [2.0.3](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.2...postgres-v2.0.3) (2025-06-30)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
* **`cds-build`:** retain more build relevant options in the deployer app ([#1206](https://github.com/cap-js/cds-dbs/issues/1206)) ([e7ed70f](https://github.com/cap-js/cds-dbs/commit/e7ed70f36920867ec0063d29255e3681dec1b60c))
|
|
13
|
+
|
|
14
|
+
## [2.0.2](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.1...postgres-v2.0.2) (2025-06-04)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
* Allow raw streams to have empty results ([#1224](https://github.com/cap-js/cds-dbs/issues/1224)) ([0a59e69](https://github.com/cap-js/cds-dbs/commit/0a59e69eae2f701b5c475512fd1cd83cfb586153))
|
|
20
|
+
|
|
7
21
|
## [2.0.1](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.0...postgres-v2.0.1) (2025-05-27)
|
|
8
22
|
|
|
9
23
|
|
package/cds-plugin.js
CHANGED
|
@@ -5,19 +5,22 @@ if (!cds.env.fiori.lean_draft) {
|
|
|
5
5
|
throw new Error('"@cap-js/postgres" only works if cds.fiori.lean_draft is enabled. Please adapt your configuration.')
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
// copy over build relevant cds options to the package.json of the deployer app
|
|
9
|
+
const CDS_BUILD_OPTIONS = ['assert_integrity']
|
|
10
|
+
|
|
11
|
+
// cdsc options are build relevant too, but we need to filter out some
|
|
12
|
+
const CDSC_DISALLOW = ['moduleLookupDirectories']
|
|
13
|
+
|
|
8
14
|
// requires @sap/cds-dk version >= 7.5.0
|
|
9
15
|
cds.build?.register?.('postgres', class PostgresBuildPlugin extends cds.build.Plugin {
|
|
10
|
-
|
|
11
16
|
static taskDefaults = { src: cds.env.folders.db }
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
init() {
|
|
17
|
+
static hasTask () { return cds.requires.db?.kind === 'postgres' }
|
|
18
|
+
init () {
|
|
16
19
|
// different from the default build output structure
|
|
17
20
|
this.task.dest = path.join(cds.root, cds.env.build.target !== '.' ? cds.env.build.target : 'gen', 'pg')
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
async build() {
|
|
23
|
+
async build () {
|
|
21
24
|
const model = await this.model()
|
|
22
25
|
if (!model) return
|
|
23
26
|
|
|
@@ -27,23 +30,36 @@ cds.build?.register?.('postgres', class PostgresBuildPlugin extends cds.build.Pl
|
|
|
27
30
|
} else {
|
|
28
31
|
const packageJson = {
|
|
29
32
|
dependencies: {
|
|
30
|
-
'@sap/cds': '^
|
|
31
|
-
'@cap-js/postgres': '^
|
|
33
|
+
'@sap/cds': '^9',
|
|
34
|
+
'@cap-js/postgres': '^2'
|
|
32
35
|
},
|
|
33
|
-
scripts: {
|
|
34
|
-
|
|
36
|
+
scripts: { start: 'cds-deploy' }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// propagate cds.env.features (allow-listed)
|
|
40
|
+
const envFeatures = cds.env?.features ?? {}
|
|
41
|
+
for (const name of CDS_BUILD_OPTIONS) {
|
|
42
|
+
const val = envFeatures[name]
|
|
43
|
+
if (val !== undefined) {
|
|
44
|
+
packageJson.cds ??= {}
|
|
45
|
+
packageJson.cds.features ??= {}
|
|
46
|
+
packageJson.cds.features[name] = val
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
|
|
50
|
+
// propagate cds.env.cdsc (minus disallowed)
|
|
51
|
+
const envCdsc = cds.env?.cdsc ?? {}
|
|
52
|
+
const cdscClean = Object.fromEntries(
|
|
53
|
+
Object.entries(envCdsc).filter(([key]) => !CDSC_DISALLOW.includes(key))
|
|
54
|
+
)
|
|
55
|
+
if (Object.keys(cdscClean).length) {
|
|
39
56
|
packageJson.cds ??= {}
|
|
40
|
-
packageJson.cds.
|
|
41
|
-
packageJson.cds.features.assert_integrity = assertIntegrity
|
|
57
|
+
packageJson.cds.cdsc = cdscClean
|
|
42
58
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
)
|
|
59
|
+
|
|
60
|
+
promises.push(this.write(packageJson).to('package.json'))
|
|
46
61
|
}
|
|
62
|
+
|
|
47
63
|
promises.push(this.write(cds.compile.to.json(model)).to(path.join('db', 'csn.json')))
|
|
48
64
|
|
|
49
65
|
let data
|
package/lib/PostgresService.js
CHANGED
|
@@ -48,8 +48,10 @@ class PostgresService extends SQLService {
|
|
|
48
48
|
ca: cr.sslrootcert,
|
|
49
49
|
}),
|
|
50
50
|
}
|
|
51
|
-
const dbc = new Client({...credentials, ...clientOptions})
|
|
51
|
+
const dbc = new Client({ ...credentials, ...clientOptions })
|
|
52
52
|
await dbc.connect()
|
|
53
|
+
dbc.open = true
|
|
54
|
+
dbc.on('end', () => { dbc.open = false })
|
|
53
55
|
return dbc
|
|
54
56
|
},
|
|
55
57
|
destroy: dbc => dbc.end(),
|
|
@@ -283,7 +285,7 @@ GROUP BY k
|
|
|
283
285
|
return target && this.run(cds.ql.CREATE(target))
|
|
284
286
|
}
|
|
285
287
|
}
|
|
286
|
-
|
|
288
|
+
|
|
287
289
|
try {
|
|
288
290
|
return await super.onPlainSQL(req, next)
|
|
289
291
|
}
|
|
@@ -367,8 +369,8 @@ GROUP BY k
|
|
|
367
369
|
const nulls = c.nulls || (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? 'LAST' : 'FIRST')
|
|
368
370
|
const o = localized
|
|
369
371
|
? this.expr(c) +
|
|
370
|
-
|
|
371
|
-
|
|
372
|
+
(c.element?.[this.class._localized] && locale ? ` COLLATE "${locale}"` : '') +
|
|
373
|
+
(c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC' : ' ASC')
|
|
372
374
|
: this.expr(c) + (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC' : ' ASC')
|
|
373
375
|
return o + ' NULLS ' + (nulls.toLowerCase() === 'first' ? 'FIRST' : 'LAST')
|
|
374
376
|
})
|
|
@@ -379,7 +381,7 @@ GROUP BY k
|
|
|
379
381
|
}
|
|
380
382
|
|
|
381
383
|
orderByICU(orderBy, localized) {
|
|
382
|
-
const locale = this.context.locale
|
|
384
|
+
const locale = this.context.locale ? `${this.context.locale.replace('_', '-')}-x-icu` : this.context.locale
|
|
383
385
|
return this._orderBy(orderBy, localized, locale)
|
|
384
386
|
}
|
|
385
387
|
|
|
@@ -710,14 +712,19 @@ class QueryStream extends Query {
|
|
|
710
712
|
this.push = this.stream.push.bind(this.stream)
|
|
711
713
|
|
|
712
714
|
this._prom = new Promise((resolve, reject) => {
|
|
715
|
+
let hasData = false
|
|
713
716
|
this.once('error', reject)
|
|
714
717
|
this.once('end', () => {
|
|
715
|
-
if (!objectMode && !this._one)
|
|
718
|
+
if (!objectMode && !this._one) {
|
|
719
|
+
if (!hasData) this.push(this.constructor.open)
|
|
720
|
+
this.push(this.constructor.close)
|
|
721
|
+
}
|
|
716
722
|
this.push(null)
|
|
717
723
|
if (this.stream.isPaused()) this.stream.resume()
|
|
718
|
-
resolve(null)
|
|
724
|
+
resolve(this._one ? null : this.stream)
|
|
719
725
|
})
|
|
720
726
|
this.once('row', row => {
|
|
727
|
+
hasData = true
|
|
721
728
|
if (row == null) return resolve(null)
|
|
722
729
|
resolve(this.stream)
|
|
723
730
|
})
|
package/package.json
CHANGED