@cap-js/sqlite 1.3.0 → 1.4.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 CHANGED
@@ -1,12 +1,36 @@
1
- # Change Log
1
+ # Changelog
2
2
 
3
3
  - All notable changes to this project are documented in this file.
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.4.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.3.1...sqlite-v1.4.0) (2023-11-20)
8
+
9
+
10
+ ### Added
11
+
12
+ * **temporal data:** add time slice key to conflict clause ([#249](https://github.com/cap-js/cds-dbs/issues/249)) ([67b8edf](https://github.com/cap-js/cds-dbs/commit/67b8edf9b7f6b0fbab0010d7c93ed03a01e103ed))
13
+
14
+
15
+ ### Fixed
16
+
17
+ * align time function behavior ([#322](https://github.com/cap-js/cds-dbs/issues/322)) ([c3ab40a](https://github.com/cap-js/cds-dbs/commit/c3ab40a007c105465349dd2f612178367b8e713a))
18
+ * date functions with null value ([#347](https://github.com/cap-js/cds-dbs/issues/347)) ([bdc8967](https://github.com/cap-js/cds-dbs/commit/bdc8967f07276acdb249dec42231d432e132e0d4))
19
+
20
+
21
+ ### Changed
22
+
23
+ * upgrade to better-sqlite@9 ([#334](https://github.com/cap-js/cds-dbs/issues/334)) ([5184e41](https://github.com/cap-js/cds-dbs/commit/5184e4155ccd1a2945a1fc033204e24425d70341))
24
+
25
+ ## [1.3.1](https://github.com/cap-js/cds-dbs/compare/v1.3.0...v1.3.1) (2023-10-10)
26
+
27
+ ### Changed
28
+
29
+ - Updated minimum required version of `@cap-js/db-service`.
30
+
7
31
  ## Version 1.3.0 - 2023-10-06
8
32
 
9
- ### Fixed
33
+ ### Fixed
10
34
 
11
35
  - `CURRENT_TIMESTAMP` in view definition preserves the timezone. #254
12
36
 
package/README.md CHANGED
@@ -14,7 +14,6 @@ npm add @cap-js/sqlite -D
14
14
 
15
15
  Learn more about setup and usage in the [respective database guide](https://cap.cloud.sap/docs/guides/databases-sqlite).
16
16
 
17
-
18
17
  ## Support
19
18
 
20
19
  This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/cds-dbs/issues).
@@ -23,6 +22,11 @@ This project is open to feature requests/suggestions, bug reports etc. via [GitH
23
22
 
24
23
  Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
25
24
 
25
+ ## Versioning
26
+
27
+ This library follows [Semantic Versioning](https://semver.org/).
28
+ All notable changes are documented in [CHANGELOG.md](CHANGELOG.md).
29
+
26
30
  ## Code of Conduct
27
31
 
28
32
  We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](CODE_OF_CONDUCT.md) at all times.
@@ -12,10 +12,30 @@ class SQLiteService extends SQLService {
12
12
  create: tenant => {
13
13
  const database = this.url4(tenant)
14
14
  const dbc = new sqlite(database)
15
+
16
+ const deterministic = { deterministic: true }
15
17
  dbc.function('session_context', key => dbc[$session][key])
16
- dbc.function('regexp', { deterministic: true }, (re, x) => (RegExp(re).test(x) ? 1 : 0))
17
- dbc.function('ISO', { deterministic: true }, d => d && new Date(d).toISOString())
18
- dbc.function('json_merge', { varargs: true, deterministic: true }, (...args) => args.join('').replace(/}{/g, ','))
18
+ dbc.function('regexp', deterministic, (re, x) => (RegExp(re).test(x) ? 1 : 0))
19
+ dbc.function('ISO', deterministic, d => d && new Date(d).toISOString())
20
+
21
+ // define date and time functions in js to allow for throwing errors
22
+ const isTime = /^\d{1,2}:\d{1,2}:\d{1,2}$/
23
+ const hasTimezone = /([+-]\d{1,2}:?\d{0,2}|Z)$/
24
+ const toDate = (d, allowTime = false) => {
25
+ const date = new Date(allowTime && isTime.test(d) ? `1970-01-01T${d}Z` : hasTimezone.test(d) ? d : d + 'Z')
26
+ if (Number.isNaN(date.getTime())) throw new Error(`Value does not contain a valid ${allowTime ? 'time' : 'date'} "${d}"`)
27
+ return date
28
+ }
29
+ dbc.function('year', deterministic, d => d === null ? null : toDate(d).getUTCFullYear())
30
+ dbc.function('month', deterministic, d => d === null ? null : toDate(d).getUTCMonth() + 1)
31
+ dbc.function('day', deterministic, d => d === null ? null : toDate(d).getUTCDate())
32
+ dbc.function('hour', deterministic, d => d === null ? null : toDate(d, true).getUTCHours())
33
+ dbc.function('minute', deterministic, d => d === null ? null : toDate(d, true).getUTCMinutes())
34
+ dbc.function('second', deterministic, d => d === null ? null : toDate(d, true).getUTCSeconds())
35
+
36
+ dbc.function('json_merge', { varargs: true, deterministic: true }, (...args) =>
37
+ args.join('').replace(/}{/g, ','),
38
+ )
19
39
  if (!dbc.memory) dbc.pragma('journal_mode = WAL')
20
40
  return dbc
21
41
  },
@@ -136,7 +156,6 @@ class SQLiteService extends SQLService {
136
156
  }
137
157
 
138
158
  static CQN2SQL = class CQN2SQLite extends SQLService.CQN2SQL {
139
-
140
159
  column_alias4(x, q) {
141
160
  let alias = super.column_alias4(x, q)
142
161
  if (alias) return alias
@@ -201,13 +220,7 @@ class SQLiteService extends SQLService {
201
220
  }
202
221
 
203
222
  // Used for SQL function expressions
204
- static Functions = { ...super.Functions,
205
- // Ensure ISO strings are returned for date/time functions
206
- current_timestamp: () => 'ISO(current_timestamp)',
207
- // SQLite doesn't support arguments for current_date and current_time
208
- current_date: () => 'current_date',
209
- current_time: () => 'current_time',
210
- }
223
+ static Functions = { ...super.Functions, ...require('./func') }
211
224
 
212
225
  // Used for CREATE TABLE statements
213
226
  static TypeMap = {
@@ -219,8 +232,12 @@ class SQLiteService extends SQLService {
219
232
  Timestamp: () => 'TIMESTAMP_TEXT',
220
233
  }
221
234
 
222
- get is_distinct_from_() { return 'is not' }
223
- get is_not_distinct_from_() { return 'is' }
235
+ get is_distinct_from_() {
236
+ return 'is not'
237
+ }
238
+ get is_not_distinct_from_() {
239
+ return 'is'
240
+ }
224
241
 
225
242
  static ReservedWords = { ...super.ReservedWords, ...require('./ReservedWords.json') }
226
243
  }
package/lib/func.js ADDED
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ const StandardFunctions = {
4
+ // Ensure ISO strings are returned for date/time functions
5
+ current_timestamp: () => 'ISO(current_timestamp)',
6
+ // SQLite doesn't support arguments for current_date and current_time
7
+ current_date: () => 'current_date',
8
+ current_time: () => 'current_time',
9
+ }
10
+
11
+ const HANAFunctions = {
12
+ /** defined in db-service */
13
+ }
14
+
15
+ for (let each in HANAFunctions) HANAFunctions[each.toUpperCase()] = HANAFunctions[each]
16
+
17
+ module.exports = { ...StandardFunctions, ...HANAFunctions }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/sqlite",
3
- "version": "1.3.0",
3
+ "version": "1.4.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,8 +30,8 @@
30
30
  "test": "jest --silent"
31
31
  },
32
32
  "dependencies": {
33
- "@cap-js/db-service": "^1.3.0",
34
- "better-sqlite3": "^8"
33
+ "@cap-js/db-service": "^1.3.1",
34
+ "better-sqlite3": "^9"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@sap/cds": ">=7"