@cap-js/sqlite 1.3.1 → 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,10 +1,28 @@
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
- ## Version 1.3.1 - 2023-10-10
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)
8
26
 
9
27
  ### Changed
10
28
 
@@ -12,7 +30,7 @@
12
30
 
13
31
  ## Version 1.3.0 - 2023-10-06
14
32
 
15
- ### Fixed
33
+ ### Fixed
16
34
 
17
35
  - `CURRENT_TIMESTAMP` in view definition preserves the timezone. #254
18
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,9 +12,27 @@ 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('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
+
18
36
  dbc.function('json_merge', { varargs: true, deterministic: true }, (...args) =>
19
37
  args.join('').replace(/}{/g, ','),
20
38
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/sqlite",
3
- "version": "1.3.1",
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": {
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@cap-js/db-service": "^1.3.1",
34
- "better-sqlite3": "^8"
34
+ "better-sqlite3": "^9"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@sap/cds": ">=7"