@cap-js/sqlite 1.5.1 → 1.7.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 +30 -0
- package/lib/SQLiteService.js +23 -12
- package/package.json +2 -2
- package/lib/ReservedWords.json +0 -149
- /package/lib/{func.js → cql-functions.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,36 @@
|
|
|
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.7.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.6.0...sqlite-v1.7.0) (2024-05-08)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
* select decimals as strings if cds.env.features.string_decimals ([#616](https://github.com/cap-js/cds-dbs/issues/616)) ([39addbf](https://github.com/cap-js/cds-dbs/commit/39addbfe01da757d86a4d65e62eda86e59fc9b87))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
* Change `sql` property to `query` for errors ([#611](https://github.com/cap-js/cds-dbs/issues/611)) ([585577a](https://github.com/cap-js/cds-dbs/commit/585577a9817e7749fb71958c26c4bfa20981c663))
|
|
18
|
+
* Improved placeholders and limit clause ([#567](https://github.com/cap-js/cds-dbs/issues/567)) ([d5d5dbb](https://github.com/cap-js/cds-dbs/commit/d5d5dbb7219bcef6134440715cf756fdd439f076))
|
|
19
|
+
|
|
20
|
+
## [1.6.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.5.1...sqlite-v1.6.0) (2024-03-22)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
* forUpdate and forShareLock ([#148](https://github.com/cap-js/cds-dbs/issues/148)) ([99a1170](https://github.com/cap-js/cds-dbs/commit/99a1170e61de4fd0c505834c25a9c03fc34da85b))
|
|
26
|
+
* **hana:** drop prepared statements after end of transaction ([#537](https://github.com/cap-js/cds-dbs/issues/537)) ([b1f864e](https://github.com/cap-js/cds-dbs/commit/b1f864e0a3a0e5efacd803d3709379cab76d61cc))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
* **`sqlite`:** use keyword list from compiler ([#526](https://github.com/cap-js/cds-dbs/issues/526)) ([a227c61](https://github.com/cap-js/cds-dbs/commit/a227c61312ba9e7d6a54944c822d5de0bb2d3f3c))
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
* this package now requires `@cap-js/db-service >= v1.7.0` ([#545](https://github.com/cap-js/cds-dbs/issues/545)) ([2cec27d](https://github.com/cap-js/cds-dbs/commit/2cec27d91402804c3b2da25cc7169f0d81a7406a))
|
|
36
|
+
|
|
7
37
|
## [1.5.1](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.5.0...sqlite-v1.5.1) (2024-02-16)
|
|
8
38
|
|
|
9
39
|
|
package/lib/SQLiteService.js
CHANGED
|
@@ -5,6 +5,13 @@ const $session = Symbol('dbc.session')
|
|
|
5
5
|
const convStrm = require('stream/consumers')
|
|
6
6
|
const { Readable } = require('stream')
|
|
7
7
|
|
|
8
|
+
const keywords = cds.compiler.to.sql.sqlite.keywords
|
|
9
|
+
// keywords come as array
|
|
10
|
+
const sqliteKeywords = keywords.reduce((prev, curr) => {
|
|
11
|
+
prev[curr] = 1
|
|
12
|
+
return prev
|
|
13
|
+
}, {})
|
|
14
|
+
|
|
8
15
|
class SQLiteService extends SQLService {
|
|
9
16
|
init() {
|
|
10
17
|
return super.init(...arguments)
|
|
@@ -73,7 +80,7 @@ class SQLiteService extends SQLService {
|
|
|
73
80
|
stream: (..._) => this._stream(stmt, ..._),
|
|
74
81
|
}
|
|
75
82
|
} catch (e) {
|
|
76
|
-
e.message += ' in:\n' + (e.
|
|
83
|
+
e.message += ' in:\n' + (e.query = sql)
|
|
77
84
|
throw e
|
|
78
85
|
}
|
|
79
86
|
}
|
|
@@ -160,7 +167,8 @@ class SQLiteService extends SQLService {
|
|
|
160
167
|
}
|
|
161
168
|
|
|
162
169
|
val(v) {
|
|
163
|
-
if (
|
|
170
|
+
if (typeof v.val === 'boolean') v.val = v.val ? 1 : 0
|
|
171
|
+
else if (Buffer.isBuffer(v.val)) v.val = v.val.toString('base64')
|
|
164
172
|
// intercept DateTime values and convert to Date objects to compare ISO Strings
|
|
165
173
|
else if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(.\d{1,9})?(Z|[+-]\d{2}(:?\d{2})?)$/.test(v.val)) {
|
|
166
174
|
const date = new Date(v.val)
|
|
@@ -171,15 +179,21 @@ class SQLiteService extends SQLService {
|
|
|
171
179
|
return super.val(v)
|
|
172
180
|
}
|
|
173
181
|
|
|
182
|
+
forUpdate() {
|
|
183
|
+
return ''
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
forShareLock() {
|
|
187
|
+
return ''
|
|
188
|
+
}
|
|
189
|
+
|
|
174
190
|
// Used for INSERT statements
|
|
175
191
|
static InputConverters = {
|
|
176
192
|
...super.InputConverters,
|
|
177
|
-
|
|
178
193
|
// The following allows passing in ISO strings with non-zulu
|
|
179
194
|
// timezones and converts them into zulu dates and times
|
|
180
195
|
Date: e => `strftime('%Y-%m-%d',${e})`,
|
|
181
196
|
Time: e => `strftime('%H:%M:%S',${e})`,
|
|
182
|
-
|
|
183
197
|
// Both, DateTimes and Timestamps are canonicalized to ISO strings with
|
|
184
198
|
// ms precision to allow safe comparisons, also to query {val}s in where clauses
|
|
185
199
|
DateTime: e => `ISO(${e})`,
|
|
@@ -188,34 +202,31 @@ class SQLiteService extends SQLService {
|
|
|
188
202
|
|
|
189
203
|
static OutputConverters = {
|
|
190
204
|
...super.OutputConverters,
|
|
191
|
-
|
|
192
205
|
// Structs and arrays are stored as JSON strings; the ->'$' unwraps them.
|
|
193
206
|
// Otherwise they would be added as strings to json_objects.
|
|
194
207
|
Association: expr => `${expr}->'$'`,
|
|
195
208
|
struct: expr => `${expr}->'$'`,
|
|
196
209
|
array: expr => `${expr}->'$'`,
|
|
197
|
-
|
|
198
210
|
// SQLite has no booleans so we need to convert 0 and 1
|
|
199
211
|
boolean: expr => `CASE ${expr} when 1 then 'true' when 0 then 'false' END ->'$'`,
|
|
200
|
-
|
|
201
212
|
// DateTimes are returned without ms added by InputConverters
|
|
202
213
|
DateTime: e => `substr(${e},0,20)||'Z'`,
|
|
203
|
-
|
|
204
214
|
// Timestamps are returned with ms, as written by InputConverters.
|
|
205
215
|
// And as cds.builtin.classes.Timestamp inherits from DateTime we need
|
|
206
216
|
// to override the DateTime converter above
|
|
207
217
|
Timestamp: undefined,
|
|
208
|
-
|
|
209
218
|
// int64 is stored as native int64 for best comparison
|
|
210
219
|
// Reading int64 as string to not loose precision
|
|
211
220
|
Int64: expr => `CAST(${expr} as TEXT)`,
|
|
212
|
-
|
|
221
|
+
// REVISIT: always cast to string in next major
|
|
222
|
+
// Reading decimal as string to not loose precision
|
|
223
|
+
Decimal: cds.env.features.string_decimals ? expr => `CAST(${expr} as TEXT)` : undefined,
|
|
213
224
|
// Binary is not allowed in json objects
|
|
214
225
|
Binary: expr => `${expr} || ''`,
|
|
215
226
|
}
|
|
216
227
|
|
|
217
228
|
// Used for SQL function expressions
|
|
218
|
-
static Functions = { ...super.Functions, ...require('./
|
|
229
|
+
static Functions = { ...super.Functions, ...require('./cql-functions') }
|
|
219
230
|
|
|
220
231
|
// Used for CREATE TABLE statements
|
|
221
232
|
static TypeMap = {
|
|
@@ -234,7 +245,7 @@ class SQLiteService extends SQLService {
|
|
|
234
245
|
return 'is'
|
|
235
246
|
}
|
|
236
247
|
|
|
237
|
-
static ReservedWords = { ...super.ReservedWords, ...
|
|
248
|
+
static ReservedWords = { ...super.ReservedWords, ...sqliteKeywords }
|
|
238
249
|
}
|
|
239
250
|
|
|
240
251
|
// REALLY REVISIT: Here we are doing error handling which we probably never should have started.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/sqlite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"test": "jest --silent"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@cap-js/db-service": "^1.
|
|
33
|
+
"@cap-js/db-service": "^1.9.0",
|
|
34
34
|
"better-sqlite3": "^9.3.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
package/lib/ReservedWords.json
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ABORT": 1,
|
|
3
|
-
"ACTION": 1,
|
|
4
|
-
"ADD": 1,
|
|
5
|
-
"AFTER": 1,
|
|
6
|
-
"ALL": 1,
|
|
7
|
-
"ALTER": 1,
|
|
8
|
-
"ALWAYS": 1,
|
|
9
|
-
"ANALYZE": 1,
|
|
10
|
-
"AND": 1,
|
|
11
|
-
"AS": 1,
|
|
12
|
-
"ASC": 1,
|
|
13
|
-
"ATTACH": 1,
|
|
14
|
-
"AUTOINCREMENT": 1,
|
|
15
|
-
"BEFORE": 1,
|
|
16
|
-
"BEGIN": 1,
|
|
17
|
-
"BETWEEN": 1,
|
|
18
|
-
"BY": 1,
|
|
19
|
-
"CASCADE": 1,
|
|
20
|
-
"CASE": 1,
|
|
21
|
-
"CAST": 1,
|
|
22
|
-
"CHECK": 1,
|
|
23
|
-
"COLLATE": 1,
|
|
24
|
-
"COLUMN": 1,
|
|
25
|
-
"COMMIT": 1,
|
|
26
|
-
"CONFLICT": 1,
|
|
27
|
-
"CONSTRAINT": 1,
|
|
28
|
-
"CREATE": 1,
|
|
29
|
-
"CROSS": 1,
|
|
30
|
-
"CURRENT": 1,
|
|
31
|
-
"CURRENT_DATE": 1,
|
|
32
|
-
"CURRENT_TIME": 1,
|
|
33
|
-
"CURRENT_TIMESTAMP": 1,
|
|
34
|
-
"DATABASE": 1,
|
|
35
|
-
"DEFAULT": 1,
|
|
36
|
-
"DEFERRABLE": 1,
|
|
37
|
-
"DEFERRED": 1,
|
|
38
|
-
"DELETE": 1,
|
|
39
|
-
"DESC": 1,
|
|
40
|
-
"DETACH": 1,
|
|
41
|
-
"DISTINCT": 1,
|
|
42
|
-
"DO": 1,
|
|
43
|
-
"DROP": 1,
|
|
44
|
-
"EACH": 1,
|
|
45
|
-
"ELSE": 1,
|
|
46
|
-
"END": 1,
|
|
47
|
-
"ESCAPE": 1,
|
|
48
|
-
"EXCEPT": 1,
|
|
49
|
-
"EXCLUDE": 1,
|
|
50
|
-
"EXCLUSIVE": 1,
|
|
51
|
-
"EXISTS": 1,
|
|
52
|
-
"EXPLAIN": 1,
|
|
53
|
-
"FAIL": 1,
|
|
54
|
-
"FILTER": 1,
|
|
55
|
-
"FIRST": 1,
|
|
56
|
-
"FOLLOWING": 1,
|
|
57
|
-
"FOR": 1,
|
|
58
|
-
"FOREIGN": 1,
|
|
59
|
-
"FROM": 1,
|
|
60
|
-
"FULL": 1,
|
|
61
|
-
"GENERATED": 1,
|
|
62
|
-
"GLOB": 1,
|
|
63
|
-
"GROUP": 1,
|
|
64
|
-
"GROUPS": 1,
|
|
65
|
-
"HAVING": 1,
|
|
66
|
-
"IF": 1,
|
|
67
|
-
"IGNORE": 1,
|
|
68
|
-
"IMMEDIATE": 1,
|
|
69
|
-
"IN": 1,
|
|
70
|
-
"INDEX": 1,
|
|
71
|
-
"INDEXED": 1,
|
|
72
|
-
"INITIALLY": 1,
|
|
73
|
-
"INNER": 1,
|
|
74
|
-
"INSERT": 1,
|
|
75
|
-
"INSTEAD": 1,
|
|
76
|
-
"INTERSECT": 1,
|
|
77
|
-
"INTO": 1,
|
|
78
|
-
"IS": 1,
|
|
79
|
-
"ISNULL": 1,
|
|
80
|
-
"JOIN": 1,
|
|
81
|
-
"KEY": 1,
|
|
82
|
-
"LAST": 1,
|
|
83
|
-
"LEFT": 1,
|
|
84
|
-
"LIKE": 1,
|
|
85
|
-
"LIMIT": 1,
|
|
86
|
-
"MATCH": 1,
|
|
87
|
-
"MATERIALIZED": 1,
|
|
88
|
-
"NATURAL": 1,
|
|
89
|
-
"NO": 1,
|
|
90
|
-
"NOT": 1,
|
|
91
|
-
"NOTHING": 1,
|
|
92
|
-
"NOTNULL": 1,
|
|
93
|
-
"NULL": 1,
|
|
94
|
-
"NULLS": 1,
|
|
95
|
-
"OF": 1,
|
|
96
|
-
"OFFSET": 1,
|
|
97
|
-
"ON": 1,
|
|
98
|
-
"OR": 1,
|
|
99
|
-
"ORDER": 1,
|
|
100
|
-
"OTHERS": 1,
|
|
101
|
-
"OUTER": 1,
|
|
102
|
-
"OVER": 1,
|
|
103
|
-
"PARTITION": 1,
|
|
104
|
-
"PLAN": 1,
|
|
105
|
-
"PRAGMA": 1,
|
|
106
|
-
"PRECEDING": 1,
|
|
107
|
-
"PRIMARY": 1,
|
|
108
|
-
"QUERY": 1,
|
|
109
|
-
"RAISE": 1,
|
|
110
|
-
"RANGE": 1,
|
|
111
|
-
"RECURSIVE": 1,
|
|
112
|
-
"REFERENCES": 1,
|
|
113
|
-
"REGEXP": 1,
|
|
114
|
-
"REINDEX": 1,
|
|
115
|
-
"RELEASE": 1,
|
|
116
|
-
"RENAME": 1,
|
|
117
|
-
"REPLACE": 1,
|
|
118
|
-
"RESTRICT": 1,
|
|
119
|
-
"RETURNING": 1,
|
|
120
|
-
"RIGHT": 1,
|
|
121
|
-
"ROLLBACK": 1,
|
|
122
|
-
"ROW": 1,
|
|
123
|
-
"ROWS": 1,
|
|
124
|
-
"SAVEPOINT": 1,
|
|
125
|
-
"SELECT": 1,
|
|
126
|
-
"SET": 1,
|
|
127
|
-
"TABLE": 1,
|
|
128
|
-
"TEMP": 1,
|
|
129
|
-
"TEMPORARY": 1,
|
|
130
|
-
"THEN": 1,
|
|
131
|
-
"TIES": 1,
|
|
132
|
-
"TO": 1,
|
|
133
|
-
"TRANSACTION": 1,
|
|
134
|
-
"TRIGGER": 1,
|
|
135
|
-
"UNBOUNDED": 1,
|
|
136
|
-
"UNION": 1,
|
|
137
|
-
"UNIQUE": 1,
|
|
138
|
-
"UPDATE": 1,
|
|
139
|
-
"USING": 1,
|
|
140
|
-
"VACUUM": 1,
|
|
141
|
-
"VALUES": 1,
|
|
142
|
-
"VIEW": 1,
|
|
143
|
-
"VIRTUAL": 1,
|
|
144
|
-
"WHEN": 1,
|
|
145
|
-
"WHERE": 1,
|
|
146
|
-
"WINDOW": 1,
|
|
147
|
-
"WITH": 1,
|
|
148
|
-
"WITHOUT": 1
|
|
149
|
-
}
|
|
File without changes
|