@cap-js/postgres 2.0.0 → 2.0.2

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 CHANGED
@@ -4,6 +4,33 @@
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.2](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.1...postgres-v2.0.2) (2025-06-04)
8
+
9
+
10
+ ### Fixed
11
+
12
+ * 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))
13
+
14
+ ## [2.0.1](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.0...postgres-v2.0.1) (2025-05-27)
15
+
16
+
17
+ ### ⚠ BREAKING CHANGES
18
+
19
+ * remove PG `?` placeholder replacement ([#1180](https://github.com/cap-js/cds-dbs/issues/1180))
20
+
21
+
22
+ ### Fixed
23
+
24
+ * Enable mixing stream and normal parameters in queries ([#1179](https://github.com/cap-js/cds-dbs/issues/1179)) ([7ee8083](https://github.com/cap-js/cds-dbs/commit/7ee808365426072250dd6de87abd11215f44561a))
25
+ * hierarchies in quoted mode ([3465cba](https://github.com/cap-js/cds-dbs/commit/3465cbab579d4560d12d3b230c55b746d4d3f5a5))
26
+ * only sort by locale if locale is set ([#1193](https://github.com/cap-js/cds-dbs/issues/1193)) ([3465cba](https://github.com/cap-js/cds-dbs/commit/3465cbab579d4560d12d3b230c55b746d4d3f5a5))
27
+
28
+
29
+ ### Changed
30
+
31
+ * remove PG `?` placeholder replacement ([#1180](https://github.com/cap-js/cds-dbs/issues/1180)) ([a1e0bd9](https://github.com/cap-js/cds-dbs/commit/a1e0bd9fe8501c284d8cbfc8d79d4dddda34c087))
32
+ * remove stream_compat ([#1139](https://github.com/cap-js/cds-dbs/issues/1139)) ([#1144](https://github.com/cap-js/cds-dbs/issues/1144)) ([1b8b2d9](https://github.com/cap-js/cds-dbs/commit/1b8b2d9539cd97be2cef088c98d88ef9ec7dd1bf))
33
+
7
34
  ## [2.0.0](https://github.com/cap-js/cds-dbs/compare/postgres-v1.14.0...postgres-v2.0.0) (2025-05-07)
8
35
 
9
36
 
@@ -48,7 +48,7 @@ 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
53
  return dbc
54
54
  },
@@ -212,7 +212,7 @@ GROUP BY k
212
212
  if (isBinary) value.setEncoding('base64')
213
213
  value.pipe(paramStream)
214
214
  value.on('error', err => paramStream.emit('error', err))
215
- streams[i] = paramStream
215
+ streams.push(paramStream)
216
216
  newValues[i] = streamID
217
217
  sql = sql.replace(
218
218
  new RegExp(`\\$${i + 1}`, 'g'),
@@ -283,12 +283,7 @@ GROUP BY k
283
283
  return target && this.run(cds.ql.CREATE(target))
284
284
  }
285
285
  }
286
- // Look for ? placeholders outside of string and replace them with $n
287
- if (/('|")(\1|[^\1]*?\1)|(\?)/.exec(query)?.[3]) {
288
- let i = 1
289
- // eslint-disable-next-line no-unused-vars
290
- req.query = query.replace(/('|")(\1|[^\1]*?\1)|(\?)/g, (a, _b, _c, d, _e, _f, _g) => (d ? '$' + i++ : a))
291
- }
286
+
292
287
  try {
293
288
  return await super.onPlainSQL(req, next)
294
289
  }
@@ -372,8 +367,8 @@ GROUP BY k
372
367
  const nulls = c.nulls || (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? 'LAST' : 'FIRST')
373
368
  const o = localized
374
369
  ? this.expr(c) +
375
- (c.element?.[this.class._localized] && locale ? ` COLLATE "${locale}"` : '') +
376
- (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC' : ' ASC')
370
+ (c.element?.[this.class._localized] && locale ? ` COLLATE "${locale}"` : '') +
371
+ (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC' : ' ASC')
377
372
  : this.expr(c) + (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC' : ' ASC')
378
373
  return o + ' NULLS ' + (nulls.toLowerCase() === 'first' ? 'FIRST' : 'LAST')
379
374
  })
@@ -384,7 +379,7 @@ GROUP BY k
384
379
  }
385
380
 
386
381
  orderByICU(orderBy, localized) {
387
- const locale = `${this.context.locale.replace('_', '-')}-x-icu`
382
+ const locale = this.context.locale ? `${this.context.locale.replace('_', '-')}-x-icu` : this.context.locale
388
383
  return this._orderBy(orderBy, localized, locale)
389
384
  }
390
385
 
@@ -715,14 +710,19 @@ class QueryStream extends Query {
715
710
  this.push = this.stream.push.bind(this.stream)
716
711
 
717
712
  this._prom = new Promise((resolve, reject) => {
713
+ let hasData = false
718
714
  this.once('error', reject)
719
715
  this.once('end', () => {
720
- if (!objectMode && !this._one) this.push(this.constructor.close)
716
+ if (!objectMode && !this._one) {
717
+ if (!hasData) this.push(this.constructor.open)
718
+ this.push(this.constructor.close)
719
+ }
721
720
  this.push(null)
722
721
  if (this.stream.isPaused()) this.stream.resume()
723
- resolve(null)
722
+ resolve(this._one ? null : this.stream)
724
723
  })
725
724
  this.once('row', row => {
725
+ hasData = true
726
726
  if (row == null) return resolve(null)
727
727
  resolve(this.stream)
728
728
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/postgres",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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": {