@cap-js/postgres 1.13.0 → 1.14.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 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.14.0](https://github.com/cap-js/cds-dbs/compare/postgres-v1.13.0...postgres-v1.14.0) (2025-04-17)
8
+
9
+
10
+ ### Added
11
+
12
+ * Result set streaming ([#702](https://github.com/cap-js/cds-dbs/issues/702)) ([2fe02ea](https://github.com/cap-js/cds-dbs/commit/2fe02eafd02993e5697efbdab90ad997fb2c9e00))
13
+
7
14
  ## [1.13.0](https://github.com/cap-js/cds-dbs/compare/postgres-v1.12.0...postgres-v1.13.0) (2025-03-31)
8
15
 
9
16
 
@@ -178,9 +178,9 @@ GROUP BY k
178
178
  throw enhanceError(e, sql)
179
179
  }
180
180
  },
181
- stream: async (values, one) => {
181
+ stream: async (values, one, objectMode) => {
182
182
  try {
183
- const streamQuery = new QueryStream({ ...query, values: this._getValues(values) }, one)
183
+ const streamQuery = new QueryStream({ ...query, values: this._getValues(values) }, one, objectMode)
184
184
  return await this.dbc.query(streamQuery)
185
185
  } catch (e) {
186
186
  throw enhanceError(e, sql)
@@ -305,7 +305,8 @@ GROUP BY k
305
305
  }
306
306
  }
307
307
 
308
- async onSELECT({ query, data }) {
308
+ async onSELECT(req) {
309
+ const { query, data } = req
309
310
  // workaround for chunking odata streaming
310
311
  if (query.SELECT?.columns?.find(col => col.as === '$mediaContentType')) {
311
312
  const columns = query.SELECT.columns
@@ -323,7 +324,7 @@ GROUP BY k
323
324
  res[this.class.CQN2SQL.prototype.column_name(binary[0])] = stream
324
325
  return res
325
326
  }
326
- return super.onSELECT({ query, data })
327
+ return super.onSELECT(req)
327
328
  }
328
329
 
329
330
  async onINSERT(req) {
@@ -574,7 +575,6 @@ GROUP BY k
574
575
 
575
576
  // Convert ST types back to WKT format
576
577
  'cds.hana.ST_POINT': expr => `ST_AsText(${expr})`,
577
- 'cds.hana.ST_POINT': expr => `ST_AsText(${expr})`,
578
578
  }
579
579
  }
580
580
 
@@ -667,7 +667,7 @@ GROUP BY k
667
667
  }
668
668
 
669
669
  class QueryStream extends Query {
670
- constructor(config, one) {
670
+ constructor(config, one, objectMode) {
671
671
  // REVISIT: currently when setting the row chunk size
672
672
  // it results in an inconsistent connection state
673
673
  // if (!one) config.rows = 1000
@@ -676,6 +676,7 @@ class QueryStream extends Query {
676
676
  this._one = one || config.one
677
677
 
678
678
  this.stream = new Readable({
679
+ objectMode,
679
680
  read: this.rows
680
681
  ? () => {
681
682
  this.stream.pause()
@@ -693,7 +694,7 @@ class QueryStream extends Query {
693
694
  this._prom = new Promise((resolve, reject) => {
694
695
  this.once('error', reject)
695
696
  this.once('end', () => {
696
- if (!this._one) this.push(this.constructor.close)
697
+ if (!objectMode && !this._one) this.push(this.constructor.close)
697
698
  this.push(null)
698
699
  if (this.stream.isPaused()) this.stream.resume()
699
700
  resolve(null)
@@ -736,10 +737,15 @@ class QueryStream extends Query {
736
737
  } else {
737
738
  this.handleDataRow = msg => {
738
739
  const val = msg.fields[0]
739
- if (!this._one && val !== null) this.push(this.constructor.open)
740
+ const objectMode = this.stream.readableObjectMode
741
+ if (!objectMode && !this._one && val !== null) this.push(this.constructor.open)
740
742
  this.emit('row', val)
741
- this.push(val)
743
+ this.push(objectMode ? JSON.parse(val) : val)
744
+
742
745
  delete this.handleDataRow
746
+ if (objectMode) {
747
+ this.handleDataRow = this.handleDataRowObjectMode
748
+ }
743
749
  }
744
750
  }
745
751
  return super.handleRowDescription(msg)
@@ -751,6 +757,11 @@ class QueryStream extends Query {
751
757
  this.push(msg.fields[0])
752
758
  }
753
759
 
760
+ // Called when a new row is received
761
+ handleDataRowObjectMode(msg) {
762
+ this.push(JSON.parse(msg.fields[0]))
763
+ }
764
+
754
765
  // Called when a new binary row is received
755
766
  handleBinaryRow(msg) {
756
767
  const val = msg.fields[0] === null ? null : this._result._parsers[0](msg.fields[0])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/postgres",
3
- "version": "1.13.0",
3
+ "version": "1.14.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": {
@@ -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.19.0",
30
+ "@cap-js/db-service": "^1.20.0",
31
31
  "pg": "^8"
32
32
  },
33
33
  "peerDependencies": {