@cap-js/sqlite 1.10.0 → 2.0.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 +28 -0
- package/lib/SQLiteService.js +34 -50
- package/lib/cql-functions.js +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,34 @@
|
|
|
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.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.11.0...sqlite-v2.0.0) (2025-05-07)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
|
|
12
|
+
* update peer dependency to @sap/cds@9 ([#1178](https://github.com/cap-js/cds-dbs/issues/1178))
|
|
13
|
+
* update dependency to @cap-js/db-service@2 ([#1178](https://github.com/cap-js/cds-dbs/issues/1178))
|
|
14
|
+
* Unfiltered db constraint errors ([#1165](https://github.com/cap-js/cds-dbs/issues/1165))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
* Support for hierarchical queries ([#1093](https://github.com/cap-js/cds-dbs/issues/1093)) ([246e0b3](https://github.com/cap-js/cds-dbs/commit/246e0b38840f7e132ea49cae335b6be7a55354b3))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
* Unfiltered db constraint errors ([#1165](https://github.com/cap-js/cds-dbs/issues/1165)) ([ff39e22](https://github.com/cap-js/cds-dbs/commit/ff39e22ac6cd3f20c98bc31c1a6bb828aa009796))
|
|
25
|
+
* update peer dependency to @sap/cds@9 ([#1178](https://github.com/cap-js/cds-dbs/issues/1178)) ([#1178](https://github.com/cap-js/cds-dbs/issues/1178)) ([0507edd](https://github.com/cap-js/cds-dbs/commit/0507edd4e1dcb98983b1fb65ade1344d978b7524))
|
|
26
|
+
* update dependency to @cap-js/db-service@2 ([#1178](https://github.com/cap-js/cds-dbs/issues/1178)) ([#1178](https://github.com/cap-js/cds-dbs/issues/1178)) ([0507edd](https://github.com/cap-js/cds-dbs/commit/0507edd4e1dcb98983b1fb65ade1344d978b7524))
|
|
27
|
+
|
|
28
|
+
## [1.11.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.10.0...sqlite-v1.11.0) (2025-04-17)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
* Result set streaming ([#702](https://github.com/cap-js/cds-dbs/issues/702)) ([2fe02ea](https://github.com/cap-js/cds-dbs/commit/2fe02eafd02993e5697efbdab90ad997fb2c9e00))
|
|
34
|
+
|
|
7
35
|
## [1.10.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.9.0...sqlite-v1.10.0) (2025-03-31)
|
|
8
36
|
|
|
9
37
|
|
package/lib/SQLiteService.js
CHANGED
|
@@ -5,7 +5,6 @@ const $session = Symbol('dbc.session')
|
|
|
5
5
|
const convStrm = require('stream/consumers')
|
|
6
6
|
const { Readable } = require('stream')
|
|
7
7
|
|
|
8
|
-
const SANITIZE_VALUES = process.env.NODE_ENV === 'production' && cds.env.log.sanitize_values !== false
|
|
9
8
|
const keywords = cds.compiler.to.sql.sqlite.keywords
|
|
10
9
|
// keywords come as array
|
|
11
10
|
const sqliteKeywords = keywords.reduce((prev, curr) => {
|
|
@@ -74,7 +73,7 @@ class SQLiteService extends SQLService {
|
|
|
74
73
|
run: (..._) => this._run(stmt, ..._),
|
|
75
74
|
get: (..._) => stmt.get(..._),
|
|
76
75
|
all: (..._) => stmt.all(..._),
|
|
77
|
-
stream: (..._) => this.
|
|
76
|
+
stream: (..._) => this._allStream(stmt, ..._),
|
|
78
77
|
}
|
|
79
78
|
} catch (e) {
|
|
80
79
|
e.message += ' in:\n' + (e.query = sql)
|
|
@@ -95,7 +94,8 @@ class SQLiteService extends SQLService {
|
|
|
95
94
|
return stmt.run(binding_params)
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
async *
|
|
97
|
+
async *_iteratorRaw(rs, one) {
|
|
98
|
+
const pageSize = (1 << 16)
|
|
99
99
|
// Allow for both array and iterator result sets
|
|
100
100
|
const first = Array.isArray(rs) ? { done: !rs[0], value: rs[0] } : rs.next()
|
|
101
101
|
if (first.done) return
|
|
@@ -106,21 +106,44 @@ class SQLiteService extends SQLService {
|
|
|
106
106
|
return
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
let buffer = '[' + first.value[0]
|
|
110
110
|
// Print first value as stand alone to prevent comma check inside the loop
|
|
111
|
-
yield first.value[0]
|
|
112
111
|
for (const row of rs) {
|
|
113
|
-
|
|
112
|
+
buffer += `,${row[0]}`
|
|
113
|
+
if (buffer.length > pageSize) {
|
|
114
|
+
yield buffer
|
|
115
|
+
buffer = ''
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
buffer += ']'
|
|
119
|
+
yield buffer
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async *_iteratorObjectMode(rs) {
|
|
123
|
+
for (const row of rs) {
|
|
124
|
+
yield JSON.parse(row[0])
|
|
114
125
|
}
|
|
115
|
-
yield ']'
|
|
116
126
|
}
|
|
117
127
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
128
|
+
async _allStream(stmt, binding_params, one, objectMode) {
|
|
129
|
+
stmt = stmt.constructor.name === 'Statement' ? stmt : stmt.__proto__
|
|
130
|
+
stmt.raw(true)
|
|
131
|
+
const get = stmt.get(binding_params)
|
|
132
|
+
if (!get) return []
|
|
133
|
+
const rs = stmt.iterate(binding_params)
|
|
134
|
+
const stream = Readable.from(objectMode ? this._iteratorObjectMode(rs) : this._iteratorRaw(rs, one), { objectMode })
|
|
135
|
+
const close = () => rs.return() // finish result set when closed early
|
|
136
|
+
stream.on('error', close)
|
|
137
|
+
stream.on('close', close)
|
|
138
|
+
return stream
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
pragma(pragma, options) {
|
|
142
|
+
if (!this.dbc) return this.begin('pragma').then(tx => {
|
|
143
|
+
try { return tx.pragma(pragma, options) }
|
|
121
144
|
finally { tx.release() }
|
|
122
145
|
})
|
|
123
|
-
return this.dbc.pragma
|
|
146
|
+
return this.dbc.pragma(pragma, options)
|
|
124
147
|
}
|
|
125
148
|
|
|
126
149
|
|
|
@@ -260,45 +283,6 @@ class SQLiteService extends SQLService {
|
|
|
260
283
|
|
|
261
284
|
static ReservedWords = { ...super.ReservedWords, ...sqliteKeywords }
|
|
262
285
|
}
|
|
263
|
-
|
|
264
|
-
// REALLY REVISIT: Here we are doing error handling which we probably never should have started.
|
|
265
|
-
// And worst of all, we handed out this as APIs without documenting it, so stakeholder tests rely
|
|
266
|
-
// on that? -> we urgently need to review these stakeholder tests.
|
|
267
|
-
// And we'd also need this to be implemented by each db service, and therefore documented, correct?
|
|
268
|
-
async onINSERT(req) {
|
|
269
|
-
try {
|
|
270
|
-
return await super.onINSERT(req)
|
|
271
|
-
} catch (err) {
|
|
272
|
-
throw _not_unique(err, 'ENTITY_ALREADY_EXISTS', req.data)
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
async onUPDATE(req) {
|
|
277
|
-
try {
|
|
278
|
-
return await super.onUPDATE(req)
|
|
279
|
-
} catch (err) {
|
|
280
|
-
throw _not_unique(err, 'UNIQUE_CONSTRAINT_VIOLATION', req.data)
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// function _not_null (err) {
|
|
286
|
-
// if (err.code === "SQLITE_CONSTRAINT_NOTNULL") return Object.assign (err, {
|
|
287
|
-
// code: 'MUST_NOT_BE_NULL',
|
|
288
|
-
// target: /\.(.*?)$/.exec(err.message)[1], // here we are even constructing OData responses, with .target
|
|
289
|
-
// message: 'Value is required',
|
|
290
|
-
// })
|
|
291
|
-
// }
|
|
292
|
-
|
|
293
|
-
function _not_unique(err, code, data) {
|
|
294
|
-
if (err.message.match(/unique constraint/i))
|
|
295
|
-
return Object.assign(err, {
|
|
296
|
-
originalMessage: err.message, // FIXME: required because of next line
|
|
297
|
-
message: code, // FIXME: misusing message as code
|
|
298
|
-
code: 400, // FIXME: misusing code as (http) status
|
|
299
|
-
})
|
|
300
|
-
if (data) err.values = SANITIZE_VALUES ? ['***'] : data
|
|
301
|
-
return err
|
|
302
286
|
}
|
|
303
287
|
|
|
304
288
|
module.exports = SQLiteService
|
package/lib/cql-functions.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/sqlite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "CDS database service for SQLite",
|
|
5
5
|
"homepage": "https://github.com/cap-js/cds-dbs/tree/main/sqlite#cds-database-service-for-sqlite",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/cap-js/cds-dbs"
|
|
8
|
+
"url": "git+https://github.com/cap-js/cds-dbs.git"
|
|
9
9
|
},
|
|
10
10
|
"bugs": {
|
|
11
11
|
"url": "https://github.com/cap-js/cds-dbs/issues"
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"test": "cds-test"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@cap-js/db-service": "^
|
|
29
|
+
"@cap-js/db-service": "^2",
|
|
30
30
|
"better-sqlite3": "^11.0.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@sap/cds": ">=
|
|
33
|
+
"@sap/cds": ">=9"
|
|
34
34
|
},
|
|
35
35
|
"cds": {
|
|
36
36
|
"requires": {
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"db": "sql"
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
|
-
"license": "
|
|
53
|
+
"license": "Apache-2.0"
|
|
54
54
|
}
|