@cap-js/sqlite 1.5.0 → 1.6.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
@@ -4,6 +4,30 @@
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.6.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.5.1...sqlite-v1.6.0) (2024-03-22)
8
+
9
+
10
+ ### Added
11
+
12
+ * forUpdate and forShareLock ([#148](https://github.com/cap-js/cds-dbs/issues/148)) ([99a1170](https://github.com/cap-js/cds-dbs/commit/99a1170e61de4fd0c505834c25a9c03fc34da85b))
13
+ * **hana:** drop prepared statements after end of transaction ([#537](https://github.com/cap-js/cds-dbs/issues/537)) ([b1f864e](https://github.com/cap-js/cds-dbs/commit/b1f864e0a3a0e5efacd803d3709379cab76d61cc))
14
+
15
+
16
+ ### Fixed
17
+
18
+ * **`sqlite`:** use keyword list from compiler ([#526](https://github.com/cap-js/cds-dbs/issues/526)) ([a227c61](https://github.com/cap-js/cds-dbs/commit/a227c61312ba9e7d6a54944c822d5de0bb2d3f3c))
19
+
20
+ ### Changed
21
+
22
+ * this package now requires `@cap-js/db-service >= v1.7.0` ([#545](https://github.com/cap-js/cds-dbs/issues/545)) ([2cec27d](https://github.com/cap-js/cds-dbs/commit/2cec27d91402804c3b2da25cc7169f0d81a7406a))
23
+
24
+ ## [1.5.1](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.5.0...sqlite-v1.5.1) (2024-02-16)
25
+
26
+
27
+ ### Fixed
28
+
29
+ * **`sqlite`:** Retain Error object for unique constraint violation ([#446](https://github.com/cap-js/cds-dbs/issues/446)) ([d27ee79](https://github.com/cap-js/cds-dbs/commit/d27ee79b4c4eea8522bf5dd2a288638f54029567))
30
+
7
31
  ## [1.5.0](https://github.com/cap-js/cds-dbs/compare/sqlite-v1.4.0...sqlite-v1.5.0) (2024-02-02)
8
32
 
9
33
 
@@ -5,6 +5,13 @@ const $session = Symbol('dbc.session')
5
5
  const convStrm = require('stream/consumers')
6
6
  const { Readable } = require('stream')
7
7
 
8
+ const keywords = cds.compiler.to.sql.sqlite.keywords
9
+ // keywords come as array
10
+ const sqliteKeywords = keywords.reduce((prev, curr) => {
11
+ prev[curr] = 1
12
+ return prev
13
+ }, {})
14
+
8
15
  class SQLiteService extends SQLService {
9
16
  init() {
10
17
  return super.init(...arguments)
@@ -171,6 +178,14 @@ class SQLiteService extends SQLService {
171
178
  return super.val(v)
172
179
  }
173
180
 
181
+ forUpdate() {
182
+ return ''
183
+ }
184
+
185
+ forShareLock() {
186
+ return ''
187
+ }
188
+
174
189
  // Used for INSERT statements
175
190
  static InputConverters = {
176
191
  ...super.InputConverters,
@@ -191,7 +206,8 @@ class SQLiteService extends SQLService {
191
206
 
192
207
  // Structs and arrays are stored as JSON strings; the ->'$' unwraps them.
193
208
  // Otherwise they would be added as strings to json_objects.
194
- struct: expr => `${expr}->'$'`, // Association + Composition inherits from struct
209
+ Association: expr => `${expr}->'$'`,
210
+ struct: expr => `${expr}->'$'`,
195
211
  array: expr => `${expr}->'$'`,
196
212
 
197
213
  // SQLite has no booleans so we need to convert 0 and 1
@@ -233,7 +249,7 @@ class SQLiteService extends SQLService {
233
249
  return 'is'
234
250
  }
235
251
 
236
- static ReservedWords = { ...super.ReservedWords, ...require('./ReservedWords.json') }
252
+ static ReservedWords = { ...super.ReservedWords, ...sqliteKeywords }
237
253
  }
238
254
 
239
255
  // REALLY REVISIT: Here we are doing error handling which we probably never should have started.
@@ -244,7 +260,7 @@ class SQLiteService extends SQLService {
244
260
  try {
245
261
  return await super.onINSERT(req)
246
262
  } catch (err) {
247
- throw _not_unique(err, 'ENTITY_ALREADY_EXISTS') || err
263
+ throw _not_unique(err, 'ENTITY_ALREADY_EXISTS')
248
264
  }
249
265
  }
250
266
 
@@ -252,13 +268,13 @@ class SQLiteService extends SQLService {
252
268
  try {
253
269
  return await super.onUPDATE(req)
254
270
  } catch (err) {
255
- throw _not_unique(err, 'UNIQUE_CONSTRAINT_VIOLATION') || err
271
+ throw _not_unique(err, 'UNIQUE_CONSTRAINT_VIOLATION')
256
272
  }
257
273
  }
258
274
  }
259
275
 
260
276
  // function _not_null (err) {
261
- // if (err.code === "SQLITE_CONSTRAINT_NOTNULL") return Object.assign ({
277
+ // if (err.code === "SQLITE_CONSTRAINT_NOTNULL") return Object.assign (err, {
262
278
  // code: 'MUST_NOT_BE_NULL',
263
279
  // target: /\.(.*?)$/.exec(err.message)[1], // here we are even constructing OData responses, with .target
264
280
  // message: 'Value is required',
@@ -267,11 +283,12 @@ class SQLiteService extends SQLService {
267
283
 
268
284
  function _not_unique(err, code) {
269
285
  if (err.message.match(/unique constraint/i))
270
- return Object.assign({
286
+ return Object.assign(err, {
271
287
  originalMessage: err.message, // FIXME: required because of next line
272
288
  message: code, // FIXME: misusing message as code
273
289
  code: 400, // FIXME: misusing code as (http) status
274
290
  })
291
+ return err
275
292
  }
276
293
 
277
294
  module.exports = SQLiteService
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/sqlite",
3
- "version": "1.5.0",
3
+ "version": "1.6.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,7 +30,7 @@
30
30
  "test": "jest --silent"
31
31
  },
32
32
  "dependencies": {
33
- "@cap-js/db-service": "^1.6.0",
33
+ "@cap-js/db-service": "^1.7.0",
34
34
  "better-sqlite3": "^9.3.0"
35
35
  },
36
36
  "peerDependencies": {
@@ -1,149 +0,0 @@
1
- {
2
- "ABORT": 1,
3
- "ACTION": 1,
4
- "ADD": 1,
5
- "AFTER": 1,
6
- "ALL": 1,
7
- "ALTER": 1,
8
- "ALWAYS": 1,
9
- "ANALYZE": 1,
10
- "AND": 1,
11
- "AS": 1,
12
- "ASC": 1,
13
- "ATTACH": 1,
14
- "AUTOINCREMENT": 1,
15
- "BEFORE": 1,
16
- "BEGIN": 1,
17
- "BETWEEN": 1,
18
- "BY": 1,
19
- "CASCADE": 1,
20
- "CASE": 1,
21
- "CAST": 1,
22
- "CHECK": 1,
23
- "COLLATE": 1,
24
- "COLUMN": 1,
25
- "COMMIT": 1,
26
- "CONFLICT": 1,
27
- "CONSTRAINT": 1,
28
- "CREATE": 1,
29
- "CROSS": 1,
30
- "CURRENT": 1,
31
- "CURRENT_DATE": 1,
32
- "CURRENT_TIME": 1,
33
- "CURRENT_TIMESTAMP": 1,
34
- "DATABASE": 1,
35
- "DEFAULT": 1,
36
- "DEFERRABLE": 1,
37
- "DEFERRED": 1,
38
- "DELETE": 1,
39
- "DESC": 1,
40
- "DETACH": 1,
41
- "DISTINCT": 1,
42
- "DO": 1,
43
- "DROP": 1,
44
- "EACH": 1,
45
- "ELSE": 1,
46
- "END": 1,
47
- "ESCAPE": 1,
48
- "EXCEPT": 1,
49
- "EXCLUDE": 1,
50
- "EXCLUSIVE": 1,
51
- "EXISTS": 1,
52
- "EXPLAIN": 1,
53
- "FAIL": 1,
54
- "FILTER": 1,
55
- "FIRST": 1,
56
- "FOLLOWING": 1,
57
- "FOR": 1,
58
- "FOREIGN": 1,
59
- "FROM": 1,
60
- "FULL": 1,
61
- "GENERATED": 1,
62
- "GLOB": 1,
63
- "GROUP": 1,
64
- "GROUPS": 1,
65
- "HAVING": 1,
66
- "IF": 1,
67
- "IGNORE": 1,
68
- "IMMEDIATE": 1,
69
- "IN": 1,
70
- "INDEX": 1,
71
- "INDEXED": 1,
72
- "INITIALLY": 1,
73
- "INNER": 1,
74
- "INSERT": 1,
75
- "INSTEAD": 1,
76
- "INTERSECT": 1,
77
- "INTO": 1,
78
- "IS": 1,
79
- "ISNULL": 1,
80
- "JOIN": 1,
81
- "KEY": 1,
82
- "LAST": 1,
83
- "LEFT": 1,
84
- "LIKE": 1,
85
- "LIMIT": 1,
86
- "MATCH": 1,
87
- "MATERIALIZED": 1,
88
- "NATURAL": 1,
89
- "NO": 1,
90
- "NOT": 1,
91
- "NOTHING": 1,
92
- "NOTNULL": 1,
93
- "NULL": 1,
94
- "NULLS": 1,
95
- "OF": 1,
96
- "OFFSET": 1,
97
- "ON": 1,
98
- "OR": 1,
99
- "ORDER": 1,
100
- "OTHERS": 1,
101
- "OUTER": 1,
102
- "OVER": 1,
103
- "PARTITION": 1,
104
- "PLAN": 1,
105
- "PRAGMA": 1,
106
- "PRECEDING": 1,
107
- "PRIMARY": 1,
108
- "QUERY": 1,
109
- "RAISE": 1,
110
- "RANGE": 1,
111
- "RECURSIVE": 1,
112
- "REFERENCES": 1,
113
- "REGEXP": 1,
114
- "REINDEX": 1,
115
- "RELEASE": 1,
116
- "RENAME": 1,
117
- "REPLACE": 1,
118
- "RESTRICT": 1,
119
- "RETURNING": 1,
120
- "RIGHT": 1,
121
- "ROLLBACK": 1,
122
- "ROW": 1,
123
- "ROWS": 1,
124
- "SAVEPOINT": 1,
125
- "SELECT": 1,
126
- "SET": 1,
127
- "TABLE": 1,
128
- "TEMP": 1,
129
- "TEMPORARY": 1,
130
- "THEN": 1,
131
- "TIES": 1,
132
- "TO": 1,
133
- "TRANSACTION": 1,
134
- "TRIGGER": 1,
135
- "UNBOUNDED": 1,
136
- "UNION": 1,
137
- "UNIQUE": 1,
138
- "UPDATE": 1,
139
- "USING": 1,
140
- "VACUUM": 1,
141
- "VALUES": 1,
142
- "VIEW": 1,
143
- "VIRTUAL": 1,
144
- "WHEN": 1,
145
- "WHERE": 1,
146
- "WINDOW": 1,
147
- "WITH": 1,
148
- "WITHOUT": 1
149
- }