@cap-js/sqlite 1.7.6 → 1.7.8
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 +14 -0
- package/lib/SQLiteService.js +23 -15
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@
|
|
|
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.8](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.7.7...sqlite-v1.7.8) (2024-12-16)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
* default `[development]` URL to `:memory:` ([#926](https://github.com/cap-js/cds-dbs/issues/926)) ([51e8aa7](https://github.com/cap-js/cds-dbs/commit/51e8aa70868a78594626ba19c02ff495571e751f))
|
|
13
|
+
|
|
14
|
+
## [1.7.7](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.7.6...sqlite-v1.7.7) (2024-11-14)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
* boolean for sql_simple_queries ([#886](https://github.com/cap-js/cds-dbs/issues/886)) ([d8139fa](https://github.com/cap-js/cds-dbs/commit/d8139fa2ea0cb6bebf966ac5b781b2f8f7c67207))
|
|
20
|
+
|
|
7
21
|
## [1.7.6](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.7.5...sqlite-v1.7.6) (2024-10-30)
|
|
8
22
|
|
|
9
23
|
|
package/lib/SQLiteService.js
CHANGED
|
@@ -12,10 +12,17 @@ const sqliteKeywords = keywords.reduce((prev, curr) => {
|
|
|
12
12
|
return prev
|
|
13
13
|
}, {})
|
|
14
14
|
|
|
15
|
+
// define date and time functions in js to allow for throwing errors
|
|
16
|
+
const isTime = /^\d{1,2}:\d{1,2}:\d{1,2}$/
|
|
17
|
+
const hasTimezone = /([+-]\d{1,2}:?\d{0,2}|Z)$/
|
|
18
|
+
const toDate = (d, allowTime = false) => {
|
|
19
|
+
const date = new Date(allowTime && isTime.test(d) ? `1970-01-01T${d}Z` : hasTimezone.test(d) ? d : d + 'Z')
|
|
20
|
+
if (Number.isNaN(date.getTime())) throw new Error(`Value does not contain a valid ${allowTime ? 'time' : 'date'} "${d}"`)
|
|
21
|
+
return date
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
15
25
|
class SQLiteService extends SQLService {
|
|
16
|
-
init() {
|
|
17
|
-
return super.init(...arguments)
|
|
18
|
-
}
|
|
19
26
|
|
|
20
27
|
get factory() {
|
|
21
28
|
return {
|
|
@@ -23,27 +30,16 @@ class SQLiteService extends SQLService {
|
|
|
23
30
|
create: tenant => {
|
|
24
31
|
const database = this.url4(tenant)
|
|
25
32
|
const dbc = new sqlite(database)
|
|
26
|
-
|
|
27
33
|
const deterministic = { deterministic: true }
|
|
28
34
|
dbc.function('session_context', key => dbc[$session][key])
|
|
29
35
|
dbc.function('regexp', deterministic, (re, x) => (RegExp(re).test(x) ? 1 : 0))
|
|
30
36
|
dbc.function('ISO', deterministic, d => d && new Date(d).toISOString())
|
|
31
|
-
|
|
32
|
-
// define date and time functions in js to allow for throwing errors
|
|
33
|
-
const isTime = /^\d{1,2}:\d{1,2}:\d{1,2}$/
|
|
34
|
-
const hasTimezone = /([+-]\d{1,2}:?\d{0,2}|Z)$/
|
|
35
|
-
const toDate = (d, allowTime = false) => {
|
|
36
|
-
const date = new Date(allowTime && isTime.test(d) ? `1970-01-01T${d}Z` : hasTimezone.test(d) ? d : d + 'Z')
|
|
37
|
-
if (Number.isNaN(date.getTime())) throw new Error(`Value does not contain a valid ${allowTime ? 'time' : 'date'} "${d}"`)
|
|
38
|
-
return date
|
|
39
|
-
}
|
|
40
37
|
dbc.function('year', deterministic, d => d === null ? null : toDate(d).getUTCFullYear())
|
|
41
38
|
dbc.function('month', deterministic, d => d === null ? null : toDate(d).getUTCMonth() + 1)
|
|
42
39
|
dbc.function('day', deterministic, d => d === null ? null : toDate(d).getUTCDate())
|
|
43
40
|
dbc.function('hour', deterministic, d => d === null ? null : toDate(d, true).getUTCHours())
|
|
44
41
|
dbc.function('minute', deterministic, d => d === null ? null : toDate(d, true).getUTCMinutes())
|
|
45
42
|
dbc.function('second', deterministic, d => d === null ? null : toDate(d, true).getUTCSeconds())
|
|
46
|
-
|
|
47
43
|
if (!dbc.memory) dbc.pragma('journal_mode = WAL')
|
|
48
44
|
return dbc
|
|
49
45
|
},
|
|
@@ -118,6 +114,15 @@ class SQLiteService extends SQLService {
|
|
|
118
114
|
yield ']'
|
|
119
115
|
}
|
|
120
116
|
|
|
117
|
+
pragma (pragma, options) {
|
|
118
|
+
if (!this.dbc) return this.begin('pragma') .then (tx => {
|
|
119
|
+
try { return tx.pragma (pragma, options) }
|
|
120
|
+
finally { tx.release() }
|
|
121
|
+
})
|
|
122
|
+
return this.dbc.pragma (pragma, options)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
121
126
|
exec(sql) {
|
|
122
127
|
return this.dbc.exec(sql)
|
|
123
128
|
}
|
|
@@ -208,7 +213,10 @@ class SQLiteService extends SQLService {
|
|
|
208
213
|
struct: expr => `${expr}->'$'`,
|
|
209
214
|
array: expr => `${expr}->'$'`,
|
|
210
215
|
// SQLite has no booleans so we need to convert 0 and 1
|
|
211
|
-
boolean:
|
|
216
|
+
boolean:
|
|
217
|
+
cds.env.features.sql_simple_queries === 2
|
|
218
|
+
? undefined
|
|
219
|
+
: expr => `CASE ${expr} when 1 then 'true' when 0 then 'false' END ->'$'`,
|
|
212
220
|
// DateTimes are returned without ms added by InputConverters
|
|
213
221
|
DateTime: e => `substr(${e},0,20)||'Z'`,
|
|
214
222
|
// Timestamps are returned with ms, as written by InputConverters.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/sqlite",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.8",
|
|
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": {
|
|
@@ -37,7 +37,10 @@
|
|
|
37
37
|
"kinds": {
|
|
38
38
|
"sql": {
|
|
39
39
|
"[development]": {
|
|
40
|
-
"kind": "sqlite"
|
|
40
|
+
"kind": "sqlite",
|
|
41
|
+
"credentials": {
|
|
42
|
+
"url": ":memory:"
|
|
43
|
+
}
|
|
41
44
|
}
|
|
42
45
|
},
|
|
43
46
|
"sqlite": {
|