@cap-js/sqlite 1.10.0 → 1.11.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 +7 -0
- package/lib/SQLiteService.js +34 -10
- package/package.json +2 -2
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.11.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.10.0...sqlite-v1.11.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.10.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.9.0...sqlite-v1.10.0) (2025-03-31)
|
|
8
15
|
|
|
9
16
|
|
package/lib/SQLiteService.js
CHANGED
|
@@ -74,7 +74,7 @@ class SQLiteService extends SQLService {
|
|
|
74
74
|
run: (..._) => this._run(stmt, ..._),
|
|
75
75
|
get: (..._) => stmt.get(..._),
|
|
76
76
|
all: (..._) => stmt.all(..._),
|
|
77
|
-
stream: (..._) => this.
|
|
77
|
+
stream: (..._) => this._allStream(stmt, ..._),
|
|
78
78
|
}
|
|
79
79
|
} catch (e) {
|
|
80
80
|
e.message += ' in:\n' + (e.query = sql)
|
|
@@ -95,7 +95,8 @@ class SQLiteService extends SQLService {
|
|
|
95
95
|
return stmt.run(binding_params)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
async *
|
|
98
|
+
async *_iteratorRaw(rs, one) {
|
|
99
|
+
const pageSize = (1 << 16)
|
|
99
100
|
// Allow for both array and iterator result sets
|
|
100
101
|
const first = Array.isArray(rs) ? { done: !rs[0], value: rs[0] } : rs.next()
|
|
101
102
|
if (first.done) return
|
|
@@ -106,21 +107,44 @@ class SQLiteService extends SQLService {
|
|
|
106
107
|
return
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
|
|
110
|
+
let buffer = '[' + first.value[0]
|
|
110
111
|
// Print first value as stand alone to prevent comma check inside the loop
|
|
111
|
-
yield first.value[0]
|
|
112
112
|
for (const row of rs) {
|
|
113
|
-
|
|
113
|
+
buffer += `,${row[0]}`
|
|
114
|
+
if (buffer.length > pageSize) {
|
|
115
|
+
yield buffer
|
|
116
|
+
buffer = ''
|
|
117
|
+
}
|
|
114
118
|
}
|
|
115
|
-
|
|
119
|
+
buffer += ']'
|
|
120
|
+
yield buffer
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async *_iteratorObjectMode(rs) {
|
|
124
|
+
for (const row of rs) {
|
|
125
|
+
yield JSON.parse(row[0])
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async _allStream(stmt, binding_params, one, objectMode) {
|
|
130
|
+
stmt = stmt.constructor.name === 'Statement' ? stmt : stmt.__proto__
|
|
131
|
+
stmt.raw(true)
|
|
132
|
+
const get = stmt.get(binding_params)
|
|
133
|
+
if (!get) return []
|
|
134
|
+
const rs = stmt.iterate(binding_params)
|
|
135
|
+
const stream = Readable.from(objectMode ? this._iteratorObjectMode(rs) : this._iteratorRaw(rs, one), { objectMode })
|
|
136
|
+
const close = () => rs.return() // finish result set when closed early
|
|
137
|
+
stream.on('error', close)
|
|
138
|
+
stream.on('close', close)
|
|
139
|
+
return stream
|
|
116
140
|
}
|
|
117
141
|
|
|
118
|
-
pragma
|
|
119
|
-
if (!this.dbc) return this.begin('pragma')
|
|
120
|
-
try { return tx.pragma
|
|
142
|
+
pragma(pragma, options) {
|
|
143
|
+
if (!this.dbc) return this.begin('pragma').then(tx => {
|
|
144
|
+
try { return tx.pragma(pragma, options) }
|
|
121
145
|
finally { tx.release() }
|
|
122
146
|
})
|
|
123
|
-
return this.dbc.pragma
|
|
147
|
+
return this.dbc.pragma(pragma, options)
|
|
124
148
|
}
|
|
125
149
|
|
|
126
150
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/sqlite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test": "cds-test"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@cap-js/db-service": "^1.
|
|
29
|
+
"@cap-js/db-service": "^1.20.0",
|
|
30
30
|
"better-sqlite3": "^11.0.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|