@cap-js/sqlite 1.2.1 → 1.3.1

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
@@ -4,6 +4,18 @@
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
8
+
9
+ ### Changed
10
+
11
+ - Updated minimum required version of `@cap-js/db-service`.
12
+
13
+ ## Version 1.3.0 - 2023-10-06
14
+
15
+ ### Fixed
16
+
17
+ - `CURRENT_TIMESTAMP` in view definition preserves the timezone. #254
18
+
7
19
  ## Version 1.2.1 - 2023-09-08
8
20
 
9
21
  ### Fixed
package/README.md CHANGED
@@ -2,5 +2,31 @@
2
2
 
3
3
  Welcome to the new SQLite database service for [SAP Cloud Application Programming Model](https://cap.cloud.sap) Node.js, based on new, streamlined database architecture and [*better-sqlite* driver](https://www.npmjs.com/package/better-sqlite3) .
4
4
 
5
- Find documentation at https://cap.cloud.sap/docs/guides/databases-sqlite.
5
+ ## Setup
6
6
 
7
+ In general, all you need to do is to install one of the database packages, as follows:
8
+
9
+ Using SQLite for development:
10
+
11
+ ```sh
12
+ npm add @cap-js/sqlite -D
13
+ ```
14
+
15
+ Learn more about setup and usage in the [respective database guide](https://cap.cloud.sap/docs/guides/databases-sqlite).
16
+
17
+
18
+ ## Support
19
+
20
+ This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/cds-dbs/issues).
21
+
22
+ ## Contribution
23
+
24
+ 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
+
26
+ ## Code of Conduct
27
+
28
+ 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.
29
+
30
+ ## Licensing
31
+
32
+ Copyright 2023 SAP SE or an SAP affiliate company and cds-dbs contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js/cds-dbs).
@@ -15,6 +15,9 @@ class SQLiteService extends SQLService {
15
15
  dbc.function('session_context', key => dbc[$session][key])
16
16
  dbc.function('regexp', { deterministic: true }, (re, x) => (RegExp(re).test(x) ? 1 : 0))
17
17
  dbc.function('ISO', { deterministic: true }, d => d && new Date(d).toISOString())
18
+ dbc.function('json_merge', { varargs: true, deterministic: true }, (...args) =>
19
+ args.join('').replace(/}{/g, ','),
20
+ )
18
21
  if (!dbc.memory) dbc.pragma('journal_mode = WAL')
19
22
  return dbc
20
23
  },
@@ -123,8 +126,18 @@ class SQLiteService extends SQLService {
123
126
  return this.dbc.exec(sql)
124
127
  }
125
128
 
126
- static CQN2SQL = class CQN2SQLite extends SQLService.CQN2SQL {
129
+ onPlainSQL({ query, data }, next) {
130
+ if (typeof query === 'string') {
131
+ // REVISIT: this is a hack the target of $now might not be a timestamp or date time
132
+ // Add input converter to CURRENT_TIMESTAMP inside views using $now
133
+ if (/^CREATE VIEW.* CURRENT_TIMESTAMP[( ]/is.test(query)) {
134
+ query = query.replace(/CURRENT_TIMESTAMP/gi, "STRFTIME('%Y-%m-%dT%H:%M:%fZ','NOW')")
135
+ }
136
+ }
137
+ return super.onPlainSQL({ query, data }, next)
138
+ }
127
139
 
140
+ static CQN2SQL = class CQN2SQLite extends SQLService.CQN2SQL {
128
141
  column_alias4(x, q) {
129
142
  let alias = super.column_alias4(x, q)
130
143
  if (alias) return alias
@@ -189,13 +202,7 @@ class SQLiteService extends SQLService {
189
202
  }
190
203
 
191
204
  // Used for SQL function expressions
192
- static Functions = { ...super.Functions,
193
- // Ensure ISO strings are returned for date/time functions
194
- current_timestamp: () => 'ISO(current_timestamp)',
195
- // SQLite doesn't support arguments for current_date and current_time
196
- current_date: () => 'current_date',
197
- current_time: () => 'current_time',
198
- }
205
+ static Functions = { ...super.Functions, ...require('./func') }
199
206
 
200
207
  // Used for CREATE TABLE statements
201
208
  static TypeMap = {
@@ -207,8 +214,12 @@ class SQLiteService extends SQLService {
207
214
  Timestamp: () => 'TIMESTAMP_TEXT',
208
215
  }
209
216
 
210
- get is_distinct_from_() { return 'is not' }
211
- get is_not_distinct_from_() { return 'is' }
217
+ get is_distinct_from_() {
218
+ return 'is not'
219
+ }
220
+ get is_not_distinct_from_() {
221
+ return 'is'
222
+ }
212
223
 
213
224
  static ReservedWords = { ...super.ReservedWords, ...require('./ReservedWords.json') }
214
225
  }
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.2.1",
3
+ "version": "1.3.1",
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.2.1",
33
+ "@cap-js/db-service": "^1.3.1",
34
34
  "better-sqlite3": "^8"
35
35
  },
36
36
  "peerDependencies": {