@cap-js/sqlite 1.8.0 → 1.10.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 +14 -0
- package/lib/SQLiteService.js +1 -1
- package/lib/cql-functions.js +146 -3
- package/package.json +2 -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.10.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.9.0...sqlite-v1.10.0) (2025-03-31)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
* reject recursive cqn queries ([#1089](https://github.com/cap-js/cds-dbs/issues/1089)) ([f09b0f8](https://github.com/cap-js/cds-dbs/commit/f09b0f815c3788349f3d39419990cd1c00963b7d))
|
|
13
|
+
|
|
14
|
+
## [1.9.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.8.0...sqlite-v1.9.0) (2025-03-04)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
* pass through of arbitrary client options ([#1024](https://github.com/cap-js/cds-dbs/issues/1024)) ([b090ccd](https://github.com/cap-js/cds-dbs/commit/b090ccda2dfd4fa535aa0fd5be9d2fc27531db05))
|
|
20
|
+
|
|
7
21
|
## [1.8.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.7.8...sqlite-v1.8.0) (2025-01-28)
|
|
8
22
|
|
|
9
23
|
|
package/lib/SQLiteService.js
CHANGED
|
@@ -30,7 +30,7 @@ class SQLiteService extends SQLService {
|
|
|
30
30
|
options: { max: 1, ...this.options.pool },
|
|
31
31
|
create: tenant => {
|
|
32
32
|
const database = this.url4(tenant)
|
|
33
|
-
const dbc = new sqlite(database)
|
|
33
|
+
const dbc = new sqlite(database, this.options.client)
|
|
34
34
|
const deterministic = { deterministic: true }
|
|
35
35
|
dbc.function('session_context', key => dbc[$session][key])
|
|
36
36
|
dbc.function('regexp', deterministic, (re, x) => (RegExp(re).test(x) ? 1 : 0))
|
package/lib/cql-functions.js
CHANGED
|
@@ -1,15 +1,158 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const StandardFunctions = {
|
|
4
|
-
//
|
|
4
|
+
// ==============================
|
|
5
|
+
// Date and Time Functions
|
|
6
|
+
// ==============================
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Ensures ISO strings are returned for current timestamp
|
|
10
|
+
* @returns {string} - SQL statement
|
|
11
|
+
*/
|
|
5
12
|
current_timestamp: () => 'ISO(current_timestamp)',
|
|
6
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* SQLite doesn't support arguments for current_date
|
|
16
|
+
* @returns {string} - SQL statement
|
|
17
|
+
*/
|
|
7
18
|
current_date: () => 'current_date',
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* SQLite doesn't support arguments for current_time
|
|
22
|
+
* @returns {string} - SQL statement
|
|
23
|
+
*/
|
|
8
24
|
current_time: () => 'current_time',
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generates SQL statement that produces the fractional seconds of a given timestamp
|
|
28
|
+
* @param {string} x - The timestamp input
|
|
29
|
+
* @returns {string} - SQL statement
|
|
30
|
+
*/
|
|
31
|
+
fractionalseconds: x => `cast(substr(strftime('%f', ${x}), length(strftime('%f', ${x})) - 3) as REAL)`,
|
|
32
|
+
|
|
33
|
+
// ==============================
|
|
34
|
+
// String Functions
|
|
35
|
+
// ==============================
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generates SQL statement that produces a boolean value indicating whether the first string contains the second string
|
|
39
|
+
* @param {...string} args - The strings to evaluate
|
|
40
|
+
* @returns {string} - SQL statement
|
|
41
|
+
*/
|
|
42
|
+
contains: (...args) => `(ifnull(instr(${args}),0) > 0)`,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Generates SQL statement that produces the index of the first occurrence of the second string in the first string
|
|
46
|
+
* @param {string} x - The string to search
|
|
47
|
+
* @param {string} y - The substring to find
|
|
48
|
+
* @returns {string} - SQL statement
|
|
49
|
+
*/
|
|
50
|
+
indexof: (x, y) => `instr(${x},${y}) - 1`,
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Generates SQL statement that produces a boolean value indicating whether the first string starts with the second string
|
|
54
|
+
* @param {string} x - The string to evaluate
|
|
55
|
+
* @param {string} y - The prefix to check
|
|
56
|
+
* @returns {string} - SQL statement
|
|
57
|
+
*/
|
|
58
|
+
startswith: (x, y) => `coalesce(instr(${x},${y}) = 1,false)`,
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Generates SQL statement that produces a boolean value indicating whether the first string ends with the second string
|
|
62
|
+
* @param {string} x - The string to evaluate
|
|
63
|
+
* @param {string} y - The suffix to check
|
|
64
|
+
* @returns {string} - SQL statement
|
|
65
|
+
*/
|
|
66
|
+
endswith: (x, y) => `coalesce(substr(${x}, length(${x}) + 1 - length(${y})) = ${y},false)`,
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Generates SQL statement that matches the given string against a regular expression
|
|
70
|
+
* @param {string} x - The string to match
|
|
71
|
+
* @param {string} y - The regular expression
|
|
72
|
+
* @returns {string} - SQL statement
|
|
73
|
+
*/
|
|
74
|
+
matchesPattern: (x, y) => `(${x} regexp ${y})`,
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Alias for matchesPattern
|
|
78
|
+
* @param {string} x - The string to match
|
|
79
|
+
* @param {string} y - The regular expression
|
|
80
|
+
* @returns {string} - SQL statement
|
|
81
|
+
*/
|
|
82
|
+
matchespattern: (x, y) => `(${x} regexp ${y})`,
|
|
9
83
|
}
|
|
10
84
|
|
|
11
85
|
const HANAFunctions = {
|
|
12
|
-
|
|
86
|
+
// ==============================
|
|
87
|
+
// Timestamp Difference Functions
|
|
88
|
+
// ==============================
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Generates SQL statement that calculates the difference in 100-nanoseconds between two timestamps
|
|
92
|
+
* @param {string} x - Left timestamp
|
|
93
|
+
* @param {string} y - Right timestamp
|
|
94
|
+
* @returns {string} - SQL statement
|
|
95
|
+
*/
|
|
96
|
+
nano100_between: (x, y) => `(julianday(${y}) - julianday(${x})) * 864000000000`,
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Generates SQL statement that calculates the difference in seconds between two timestamps
|
|
100
|
+
* @param {string} x - Left timestamp
|
|
101
|
+
* @param {string} y - Right timestamp
|
|
102
|
+
* @returns {string} - SQL statement
|
|
103
|
+
*/
|
|
104
|
+
seconds_between: (x, y) => `(julianday(${y}) - julianday(${x})) * 86400`,
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Generates SQL statement that calculates the difference in days between two timestamps
|
|
108
|
+
* @param {string} x - Left timestamp
|
|
109
|
+
* @param {string} y - Right timestamp
|
|
110
|
+
* @returns {string} - SQL statement
|
|
111
|
+
*/
|
|
112
|
+
days_between: (x, y) => `(
|
|
113
|
+
cast(julianday(${y}) as Integer) - cast(julianday(${x}) as Integer)
|
|
114
|
+
) + (
|
|
115
|
+
case
|
|
116
|
+
when (julianday(${y}) < julianday(${x})) then
|
|
117
|
+
(cast(strftime('%H%M%S%f0000', ${y}) as Integer) < cast(strftime('%H%M%S%f0000', ${x}) as Integer))
|
|
118
|
+
else
|
|
119
|
+
(cast(strftime('%H%M%S%f0000', ${y}) as Integer) > cast(strftime('%H%M%S%f0000', ${x}) as Integer)) * -1
|
|
120
|
+
end
|
|
121
|
+
)`,
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Generates SQL statement that calculates the difference in months between two timestamps
|
|
125
|
+
* @param {string} x - Left timestamp
|
|
126
|
+
* @param {string} y - Right timestamp
|
|
127
|
+
* @returns {string} - SQL statement
|
|
128
|
+
*/
|
|
129
|
+
months_between: (x, y) => `
|
|
130
|
+
(
|
|
131
|
+
(
|
|
132
|
+
(cast(strftime('%Y', ${y}) as Integer) - cast(strftime('%Y', ${x}) as Integer)) * 12
|
|
133
|
+
) + (
|
|
134
|
+
cast(strftime('%m', ${y}) as Integer) - cast(strftime('%m', ${x}) as Integer)
|
|
135
|
+
) + (
|
|
136
|
+
(
|
|
137
|
+
case
|
|
138
|
+
when (cast(strftime('%Y%m', ${y}) as Integer) < cast(strftime('%Y%m', ${x}) as Integer)) then
|
|
139
|
+
(cast(strftime('%d%H%M%S%f0000', ${y}) as Integer) > cast(strftime('%d%H%M%S%f0000', ${x}) as Integer))
|
|
140
|
+
else
|
|
141
|
+
(cast(strftime('%d%H%M%S%f0000', ${y}) as Integer) < cast(strftime('%d%H%M%S%f0000', ${x}) as Integer)) * -1
|
|
142
|
+
end
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
)`,
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Generates SQL statement that calculates the difference in years between two timestamps
|
|
149
|
+
* @param {string} x - Left timestamp
|
|
150
|
+
* @param {string} y - Right timestamp
|
|
151
|
+
* @returns {string} - SQL statement
|
|
152
|
+
*/
|
|
153
|
+
years_between(x, y) {
|
|
154
|
+
return `floor(${this.months_between(x, y)} / 12)`
|
|
155
|
+
},
|
|
13
156
|
}
|
|
14
157
|
|
|
15
158
|
for (let each in HANAFunctions) HANAFunctions[each.toUpperCase()] = HANAFunctions[each]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/sqlite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.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.19.0",
|
|
30
30
|
"better-sqlite3": "^11.0.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|