@cap-js/db-service 1.16.1 → 1.16.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 +7 -0
- package/lib/cqn2sql.js +8 -19
- package/package.json +1 -1
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.16.2](https://github.com/cap-js/cds-dbs/compare/db-service-v1.16.1...db-service-v1.16.2) (2024-12-18)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
* do not override .toJSON of buffers ([#949](https://github.com/cap-js/cds-dbs/issues/949)) ([ed52f72](https://github.com/cap-js/cds-dbs/commit/ed52f72206df6e683106ab0bbbecf4b778cf36b5))
|
|
13
|
+
|
|
7
14
|
## [1.16.1](https://github.com/cap-js/cds-dbs/compare/db-service-v1.16.0...db-service-v1.16.1) (2024-12-16)
|
|
8
15
|
|
|
9
16
|
|
package/lib/cqn2sql.js
CHANGED
|
@@ -8,7 +8,7 @@ const { Readable } = require('stream')
|
|
|
8
8
|
|
|
9
9
|
const DEBUG = cds.debug('sql|sqlite')
|
|
10
10
|
const LOG_SQL = cds.log('sql')
|
|
11
|
-
const LOG_SQLITE =
|
|
11
|
+
const LOG_SQLITE = cds.log('sqlite')
|
|
12
12
|
|
|
13
13
|
class CQN2SQLRenderer {
|
|
14
14
|
/**
|
|
@@ -25,7 +25,7 @@ class CQN2SQLRenderer {
|
|
|
25
25
|
if (cds.env.sql.names === 'quoted') {
|
|
26
26
|
this.class.prototype.name = (name, query) => {
|
|
27
27
|
const e = name.id || name
|
|
28
|
-
return (query?.target || this.model?.definitions[e])?.['@cds.persistence.name'] || e
|
|
28
|
+
return (query?.target || this.model?.definitions[e])?.['@cds.persistence.name'] || e
|
|
29
29
|
}
|
|
30
30
|
this.class.prototype.quote = (s) => `"${String(s).replace(/"/g, '""')}"`
|
|
31
31
|
}
|
|
@@ -86,7 +86,7 @@ class CQN2SQLRenderer {
|
|
|
86
86
|
if (vars && Object.keys(vars).length && !this.values?.length) this.values = vars
|
|
87
87
|
const sanitize_values = process.env.NODE_ENV === 'production' && cds.env.log.sanitize_values !== false
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
if (DEBUG && (LOG_SQL._debug || LOG_SQLITE._debug)) {
|
|
91
91
|
let values = sanitize_values && (this.entries || this.values?.length > 0) ? ['***'] : this.entries || this.values || []
|
|
92
92
|
if (values && !Array.isArray(values)) {
|
|
@@ -95,7 +95,7 @@ class CQN2SQLRenderer {
|
|
|
95
95
|
DEBUG(this.sql, ...values)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
return this
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -528,9 +528,6 @@ class CQN2SQLRenderer {
|
|
|
528
528
|
|
|
529
529
|
async *INSERT_entries_stream(entries, binaryEncoding = 'base64') {
|
|
530
530
|
const elements = this.cqn.target?.elements || {}
|
|
531
|
-
const transformBase64 = binaryEncoding === 'base64'
|
|
532
|
-
? a => a
|
|
533
|
-
: a => a != null ? Buffer.from(a, 'base64').toString(binaryEncoding) : a
|
|
534
531
|
const bufferLimit = 65536 // 1 << 16
|
|
535
532
|
let buffer = '['
|
|
536
533
|
|
|
@@ -561,8 +558,8 @@ class CQN2SQLRenderer {
|
|
|
561
558
|
|
|
562
559
|
buffer += '"'
|
|
563
560
|
} else {
|
|
564
|
-
if (elements[key]?.type in this.BINARY_TYPES) {
|
|
565
|
-
val =
|
|
561
|
+
if (val != null && elements[key]?.type in this.BINARY_TYPES) {
|
|
562
|
+
val = Buffer.from(val, 'base64').toString(binaryEncoding)
|
|
566
563
|
}
|
|
567
564
|
buffer += `${keyJSON}${JSON.stringify(val)}`
|
|
568
565
|
}
|
|
@@ -580,9 +577,6 @@ class CQN2SQLRenderer {
|
|
|
580
577
|
|
|
581
578
|
async *INSERT_rows_stream(entries, binaryEncoding = 'base64') {
|
|
582
579
|
const elements = this.cqn.target?.elements || {}
|
|
583
|
-
const transformBase64 = binaryEncoding === 'base64'
|
|
584
|
-
? a => a
|
|
585
|
-
: a => a != null ? Buffer.from(a, 'base64').toString(binaryEncoding) : a
|
|
586
580
|
const bufferLimit = 65536 // 1 << 16
|
|
587
581
|
let buffer = '['
|
|
588
582
|
|
|
@@ -609,8 +603,8 @@ class CQN2SQLRenderer {
|
|
|
609
603
|
|
|
610
604
|
buffer += '"'
|
|
611
605
|
} else {
|
|
612
|
-
if (elements[this.columns[key]]?.type in this.BINARY_TYPES) {
|
|
613
|
-
val =
|
|
606
|
+
if (val != null && elements[this.columns[key]]?.type in this.BINARY_TYPES) {
|
|
607
|
+
val = Buffer.from(val, 'base64').toString(binaryEncoding)
|
|
614
608
|
}
|
|
615
609
|
buffer += `${sepsub}${val === undefined ? 'null' : JSON.stringify(val)}`
|
|
616
610
|
}
|
|
@@ -1149,11 +1143,6 @@ class CQN2SQLRenderer {
|
|
|
1149
1143
|
}
|
|
1150
1144
|
}
|
|
1151
1145
|
|
|
1152
|
-
// REVISIT: Workaround for JSON.stringify to work with buffers
|
|
1153
|
-
Buffer.prototype.toJSON = function () {
|
|
1154
|
-
return this.toString('base64')
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
1146
|
Readable.prototype[require('node:util').inspect.custom] = Readable.prototype.toJSON = function () { return this._raw || `[object ${this.constructor.name}]` }
|
|
1158
1147
|
|
|
1159
1148
|
const ObjectKeys = o => (o && [...ObjectKeys(o.__proto__), ...Object.keys(o)]) || []
|
package/package.json
CHANGED