@nymphjs/driver-sqlite3 1.0.0-beta.45 → 1.0.0-beta.47
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 +8 -0
- package/package.json +11 -11
- package/src/SQLite3Driver.ts +167 -167
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-beta.47](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.46...v1.0.0-beta.47) (2023-11-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @nymphjs/driver-sqlite3
|
|
9
|
+
|
|
10
|
+
# [1.0.0-beta.46](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.45...v1.0.0-beta.46) (2023-08-29)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @nymphjs/driver-sqlite3
|
|
13
|
+
|
|
6
14
|
# [1.0.0-beta.45](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.44...v1.0.0-beta.45) (2023-07-17)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @nymphjs/driver-sqlite3
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nymphjs/driver-sqlite3",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.47",
|
|
4
4
|
"description": "Nymph.js - SQLite3 DB Driver",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,17 +31,17 @@
|
|
|
31
31
|
},
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@nymphjs/guid": "^1.0.0-beta.
|
|
35
|
-
"@nymphjs/nymph": "^1.0.0-beta.
|
|
36
|
-
"better-sqlite3": "^
|
|
34
|
+
"@nymphjs/guid": "^1.0.0-beta.47",
|
|
35
|
+
"@nymphjs/nymph": "^1.0.0-beta.47",
|
|
36
|
+
"better-sqlite3": "^9.1.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@tsconfig/recommended": "^1.0.
|
|
40
|
-
"@types/better-sqlite3": "^7.6.
|
|
41
|
-
"@types/jest": "^29.5.
|
|
42
|
-
"jest": "^29.
|
|
43
|
-
"ts-jest": "^29.1.
|
|
44
|
-
"typescript": "^5.
|
|
39
|
+
"@tsconfig/recommended": "^1.0.3",
|
|
40
|
+
"@types/better-sqlite3": "^7.6.7",
|
|
41
|
+
"@types/jest": "^29.5.8",
|
|
42
|
+
"jest": "^29.7.0",
|
|
43
|
+
"ts-jest": "^29.1.1",
|
|
44
|
+
"typescript": "^5.2.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "228f0d25911d1b98859f2acf8ace3d3f251c4882"
|
|
47
47
|
}
|
package/src/SQLite3Driver.ts
CHANGED
|
@@ -44,7 +44,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
44
44
|
static escape(input: string) {
|
|
45
45
|
if (input.indexOf('\x00') !== -1) {
|
|
46
46
|
throw new InvalidParametersError(
|
|
47
|
-
'SQLite3 identifiers (like entity ETYPE) cannot contain null characters.'
|
|
47
|
+
'SQLite3 identifiers (like entity ETYPE) cannot contain null characters.',
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -106,7 +106,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
106
106
|
// Create the preg_match and regexp functions.
|
|
107
107
|
link.function('regexp', { deterministic: true }, ((
|
|
108
108
|
pattern: string,
|
|
109
|
-
subject: string
|
|
109
|
+
subject: string,
|
|
110
110
|
) => (this.posixRegexMatch(pattern, subject) ? 1 : 0)) as (
|
|
111
111
|
...params: any[]
|
|
112
112
|
) => any);
|
|
@@ -153,7 +153,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
153
153
|
if (!this.store) {
|
|
154
154
|
if (write) {
|
|
155
155
|
throw new Error(
|
|
156
|
-
'Tried to open in write without opening in read first.'
|
|
156
|
+
'Tried to open in write without opening in read first.',
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
159
|
this.store = new InternalStore(link);
|
|
@@ -171,7 +171,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
171
171
|
if (filename === ':memory:') {
|
|
172
172
|
throw new NotConfiguredError(
|
|
173
173
|
"It seems the config hasn't been set up correctly. Could not connect: " +
|
|
174
|
-
e?.message
|
|
174
|
+
e?.message,
|
|
175
175
|
);
|
|
176
176
|
} else {
|
|
177
177
|
throw new UnableToConnectError('Could not connect: ' + e?.message);
|
|
@@ -226,137 +226,137 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
226
226
|
// Create the entity table.
|
|
227
227
|
this.queryRun(
|
|
228
228
|
`CREATE TABLE IF NOT EXISTS ${SQLite3Driver.escape(
|
|
229
|
-
`${this.prefix}entities_${etype}
|
|
230
|
-
)} ("guid" CHARACTER(24) PRIMARY KEY, "tags" TEXT, "cdate" REAL NOT NULL, "mdate" REAL NOT NULL)
|
|
229
|
+
`${this.prefix}entities_${etype}`,
|
|
230
|
+
)} ("guid" CHARACTER(24) PRIMARY KEY, "tags" TEXT, "cdate" REAL NOT NULL, "mdate" REAL NOT NULL);`,
|
|
231
231
|
);
|
|
232
232
|
this.queryRun(
|
|
233
233
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
234
|
-
`${this.prefix}entities_${etype}_id_cdate
|
|
234
|
+
`${this.prefix}entities_${etype}_id_cdate`,
|
|
235
235
|
)} ON ${SQLite3Driver.escape(
|
|
236
|
-
`${this.prefix}entities_${etype}
|
|
237
|
-
)} ("cdate")
|
|
236
|
+
`${this.prefix}entities_${etype}`,
|
|
237
|
+
)} ("cdate");`,
|
|
238
238
|
);
|
|
239
239
|
this.queryRun(
|
|
240
240
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
241
|
-
`${this.prefix}entities_${etype}_id_mdate
|
|
241
|
+
`${this.prefix}entities_${etype}_id_mdate`,
|
|
242
242
|
)} ON ${SQLite3Driver.escape(
|
|
243
|
-
`${this.prefix}entities_${etype}
|
|
244
|
-
)} ("mdate")
|
|
243
|
+
`${this.prefix}entities_${etype}`,
|
|
244
|
+
)} ("mdate");`,
|
|
245
245
|
);
|
|
246
246
|
this.queryRun(
|
|
247
247
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
248
|
-
`${this.prefix}entities_${etype}_id_tags
|
|
248
|
+
`${this.prefix}entities_${etype}_id_tags`,
|
|
249
249
|
)} ON ${SQLite3Driver.escape(
|
|
250
|
-
`${this.prefix}entities_${etype}
|
|
251
|
-
)} ("tags")
|
|
250
|
+
`${this.prefix}entities_${etype}`,
|
|
251
|
+
)} ("tags");`,
|
|
252
252
|
);
|
|
253
253
|
// Create the data table.
|
|
254
254
|
this.queryRun(
|
|
255
255
|
`CREATE TABLE IF NOT EXISTS ${SQLite3Driver.escape(
|
|
256
|
-
`${this.prefix}data_${etype}
|
|
256
|
+
`${this.prefix}data_${etype}`,
|
|
257
257
|
)} ("guid" CHARACTER(24) NOT NULL REFERENCES ${SQLite3Driver.escape(
|
|
258
|
-
`${this.prefix}entities_${etype}
|
|
259
|
-
)} ("guid") ON DELETE CASCADE, "name" TEXT NOT NULL, "value" TEXT NOT NULL, PRIMARY KEY("guid", "name"))
|
|
258
|
+
`${this.prefix}entities_${etype}`,
|
|
259
|
+
)} ("guid") ON DELETE CASCADE, "name" TEXT NOT NULL, "value" TEXT NOT NULL, PRIMARY KEY("guid", "name"));`,
|
|
260
260
|
);
|
|
261
261
|
this.queryRun(
|
|
262
262
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
263
|
-
`${this.prefix}data_${etype}_id_guid
|
|
263
|
+
`${this.prefix}data_${etype}_id_guid`,
|
|
264
264
|
)} ON ${SQLite3Driver.escape(
|
|
265
|
-
`${this.prefix}data_${etype}
|
|
266
|
-
)} ("guid")
|
|
265
|
+
`${this.prefix}data_${etype}`,
|
|
266
|
+
)} ("guid");`,
|
|
267
267
|
);
|
|
268
268
|
this.queryRun(
|
|
269
269
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
270
|
-
`${this.prefix}data_${etype}_id_name
|
|
270
|
+
`${this.prefix}data_${etype}_id_name`,
|
|
271
271
|
)} ON ${SQLite3Driver.escape(
|
|
272
|
-
`${this.prefix}data_${etype}
|
|
273
|
-
)} ("name")
|
|
272
|
+
`${this.prefix}data_${etype}`,
|
|
273
|
+
)} ("name");`,
|
|
274
274
|
);
|
|
275
275
|
this.queryRun(
|
|
276
276
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
277
|
-
`${this.prefix}data_${etype}_id_value
|
|
277
|
+
`${this.prefix}data_${etype}_id_value`,
|
|
278
278
|
)} ON ${SQLite3Driver.escape(
|
|
279
|
-
`${this.prefix}data_${etype}
|
|
280
|
-
)} ("value")
|
|
279
|
+
`${this.prefix}data_${etype}`,
|
|
280
|
+
)} ("value");`,
|
|
281
281
|
);
|
|
282
282
|
this.queryRun(
|
|
283
283
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
284
|
-
`${this.prefix}data_${etype}_id_guid__name_user
|
|
284
|
+
`${this.prefix}data_${etype}_id_guid__name_user`,
|
|
285
285
|
)} ON ${SQLite3Driver.escape(
|
|
286
|
-
`${this.prefix}data_${etype}
|
|
287
|
-
)} ("guid") WHERE "name" = \'user\'
|
|
286
|
+
`${this.prefix}data_${etype}`,
|
|
287
|
+
)} ("guid") WHERE "name" = \'user\';`,
|
|
288
288
|
);
|
|
289
289
|
this.queryRun(
|
|
290
290
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
291
|
-
`${this.prefix}data_${etype}_id_guid__name_group
|
|
291
|
+
`${this.prefix}data_${etype}_id_guid__name_group`,
|
|
292
292
|
)} ON ${SQLite3Driver.escape(
|
|
293
|
-
`${this.prefix}data_${etype}
|
|
294
|
-
)} ("guid") WHERE "name" = \'group\'
|
|
293
|
+
`${this.prefix}data_${etype}`,
|
|
294
|
+
)} ("guid") WHERE "name" = \'group\';`,
|
|
295
295
|
);
|
|
296
296
|
// Create the comparisons table.
|
|
297
297
|
this.queryRun(
|
|
298
298
|
`CREATE TABLE IF NOT EXISTS ${SQLite3Driver.escape(
|
|
299
|
-
`${this.prefix}comparisons_${etype}
|
|
299
|
+
`${this.prefix}comparisons_${etype}`,
|
|
300
300
|
)} ("guid" CHARACTER(24) NOT NULL REFERENCES ${SQLite3Driver.escape(
|
|
301
|
-
`${this.prefix}entities_${etype}
|
|
302
|
-
)} ("guid") ON DELETE CASCADE, "name" TEXT NOT NULL, "truthy" INTEGER, "string" TEXT, "number" REAL, PRIMARY KEY("guid", "name"))
|
|
301
|
+
`${this.prefix}entities_${etype}`,
|
|
302
|
+
)} ("guid") ON DELETE CASCADE, "name" TEXT NOT NULL, "truthy" INTEGER, "string" TEXT, "number" REAL, PRIMARY KEY("guid", "name"));`,
|
|
303
303
|
);
|
|
304
304
|
this.queryRun(
|
|
305
305
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
306
|
-
`${this.prefix}comparisons_${etype}_id_guid
|
|
306
|
+
`${this.prefix}comparisons_${etype}_id_guid`,
|
|
307
307
|
)} ON ${SQLite3Driver.escape(
|
|
308
|
-
`${this.prefix}comparisons_${etype}
|
|
309
|
-
)} ("guid")
|
|
308
|
+
`${this.prefix}comparisons_${etype}`,
|
|
309
|
+
)} ("guid");`,
|
|
310
310
|
);
|
|
311
311
|
this.queryRun(
|
|
312
312
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
313
|
-
`${this.prefix}comparisons_${etype}_id_name
|
|
313
|
+
`${this.prefix}comparisons_${etype}_id_name`,
|
|
314
314
|
)} ON ${SQLite3Driver.escape(
|
|
315
|
-
`${this.prefix}comparisons_${etype}
|
|
316
|
-
)} ("name")
|
|
315
|
+
`${this.prefix}comparisons_${etype}`,
|
|
316
|
+
)} ("name");`,
|
|
317
317
|
);
|
|
318
318
|
this.queryRun(
|
|
319
319
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
320
|
-
`${this.prefix}comparisons_${etype}_id_name__truthy
|
|
320
|
+
`${this.prefix}comparisons_${etype}_id_name__truthy`,
|
|
321
321
|
)} ON ${SQLite3Driver.escape(
|
|
322
|
-
`${this.prefix}comparisons_${etype}
|
|
323
|
-
)} ("name") WHERE "truthy" = 1
|
|
322
|
+
`${this.prefix}comparisons_${etype}`,
|
|
323
|
+
)} ("name") WHERE "truthy" = 1;`,
|
|
324
324
|
);
|
|
325
325
|
// Create the references table.
|
|
326
326
|
this.queryRun(
|
|
327
327
|
`CREATE TABLE IF NOT EXISTS ${SQLite3Driver.escape(
|
|
328
|
-
`${this.prefix}references_${etype}
|
|
328
|
+
`${this.prefix}references_${etype}`,
|
|
329
329
|
)} ("guid" CHARACTER(24) NOT NULL REFERENCES ${SQLite3Driver.escape(
|
|
330
|
-
`${this.prefix}entities_${etype}
|
|
331
|
-
)} ("guid") ON DELETE CASCADE, "name" TEXT NOT NULL, "reference" CHARACTER(24) NOT NULL, PRIMARY KEY("guid", "name", "reference"))
|
|
330
|
+
`${this.prefix}entities_${etype}`,
|
|
331
|
+
)} ("guid") ON DELETE CASCADE, "name" TEXT NOT NULL, "reference" CHARACTER(24) NOT NULL, PRIMARY KEY("guid", "name", "reference"));`,
|
|
332
332
|
);
|
|
333
333
|
this.queryRun(
|
|
334
334
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
335
|
-
`${this.prefix}references_${etype}_id_guid
|
|
335
|
+
`${this.prefix}references_${etype}_id_guid`,
|
|
336
336
|
)} ON ${SQLite3Driver.escape(
|
|
337
|
-
`${this.prefix}references_${etype}
|
|
338
|
-
)} ("guid")
|
|
337
|
+
`${this.prefix}references_${etype}`,
|
|
338
|
+
)} ("guid");`,
|
|
339
339
|
);
|
|
340
340
|
this.queryRun(
|
|
341
341
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
342
|
-
`${this.prefix}references_${etype}_id_name
|
|
342
|
+
`${this.prefix}references_${etype}_id_name`,
|
|
343
343
|
)} ON ${SQLite3Driver.escape(
|
|
344
|
-
`${this.prefix}references_${etype}
|
|
345
|
-
)} ("name")
|
|
344
|
+
`${this.prefix}references_${etype}`,
|
|
345
|
+
)} ("name");`,
|
|
346
346
|
);
|
|
347
347
|
this.queryRun(
|
|
348
348
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
349
|
-
`${this.prefix}references_${etype}_id_reference
|
|
349
|
+
`${this.prefix}references_${etype}_id_reference`,
|
|
350
350
|
)} ON ${SQLite3Driver.escape(
|
|
351
|
-
`${this.prefix}references_${etype}
|
|
352
|
-
)} ("reference")
|
|
351
|
+
`${this.prefix}references_${etype}`,
|
|
352
|
+
)} ("reference");`,
|
|
353
353
|
);
|
|
354
354
|
} else {
|
|
355
355
|
// Create the UID table.
|
|
356
356
|
this.queryRun(
|
|
357
357
|
`CREATE TABLE IF NOT EXISTS ${SQLite3Driver.escape(
|
|
358
|
-
`${this.prefix}uids
|
|
359
|
-
)} ("name" TEXT PRIMARY KEY NOT NULL, "cur_uid" INTEGER NOT NULL)
|
|
358
|
+
`${this.prefix}uids`,
|
|
359
|
+
)} ("name" TEXT PRIMARY KEY NOT NULL, "cur_uid" INTEGER NOT NULL);`,
|
|
360
360
|
);
|
|
361
361
|
}
|
|
362
362
|
this.commit('nymph-tablecreation');
|
|
@@ -370,7 +370,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
370
370
|
private query<T extends () => any>(
|
|
371
371
|
runQuery: T,
|
|
372
372
|
query: string,
|
|
373
|
-
etypes: string[] = []
|
|
373
|
+
etypes: string[] = [],
|
|
374
374
|
): ReturnType<T> {
|
|
375
375
|
try {
|
|
376
376
|
return runQuery();
|
|
@@ -390,13 +390,13 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
390
390
|
} catch (e2: any) {
|
|
391
391
|
throw new QueryFailedError(
|
|
392
392
|
'Query failed: ' + e2?.code + ' - ' + e2?.message,
|
|
393
|
-
query
|
|
393
|
+
query,
|
|
394
394
|
);
|
|
395
395
|
}
|
|
396
396
|
} else {
|
|
397
397
|
throw new QueryFailedError(
|
|
398
398
|
'Query failed: ' + e?.code + ' - ' + e?.message,
|
|
399
|
-
query
|
|
399
|
+
query,
|
|
400
400
|
);
|
|
401
401
|
}
|
|
402
402
|
}
|
|
@@ -407,7 +407,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
407
407
|
{
|
|
408
408
|
etypes = [],
|
|
409
409
|
params = {},
|
|
410
|
-
}: { etypes?: string[]; params?: { [k: string]: any } } = {}
|
|
410
|
+
}: { etypes?: string[]; params?: { [k: string]: any } } = {},
|
|
411
411
|
) {
|
|
412
412
|
return this.query(
|
|
413
413
|
() =>
|
|
@@ -415,7 +415,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
415
415
|
.prepare(query)
|
|
416
416
|
.iterate(params),
|
|
417
417
|
`${query} -- ${JSON.stringify(params)}`,
|
|
418
|
-
etypes
|
|
418
|
+
etypes,
|
|
419
419
|
);
|
|
420
420
|
}
|
|
421
421
|
|
|
@@ -424,13 +424,13 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
424
424
|
{
|
|
425
425
|
etypes = [],
|
|
426
426
|
params = {},
|
|
427
|
-
}: { etypes?: string[]; params?: { [k: string]: any } } = {}
|
|
427
|
+
}: { etypes?: string[]; params?: { [k: string]: any } } = {},
|
|
428
428
|
) {
|
|
429
429
|
return this.query(
|
|
430
430
|
() =>
|
|
431
431
|
(this.store.linkWrite || this.store.link).prepare(query).get(params),
|
|
432
432
|
`${query} -- ${JSON.stringify(params)}`,
|
|
433
|
-
etypes
|
|
433
|
+
etypes,
|
|
434
434
|
);
|
|
435
435
|
}
|
|
436
436
|
|
|
@@ -439,20 +439,20 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
439
439
|
{
|
|
440
440
|
etypes = [],
|
|
441
441
|
params = {},
|
|
442
|
-
}: { etypes?: string[]; params?: { [k: string]: any } } = {}
|
|
442
|
+
}: { etypes?: string[]; params?: { [k: string]: any } } = {},
|
|
443
443
|
) {
|
|
444
444
|
return this.query(
|
|
445
445
|
() =>
|
|
446
446
|
(this.store.linkWrite || this.store.link).prepare(query).run(params),
|
|
447
447
|
`${query} -- ${JSON.stringify(params)}`,
|
|
448
|
-
etypes
|
|
448
|
+
etypes,
|
|
449
449
|
);
|
|
450
450
|
}
|
|
451
451
|
|
|
452
452
|
public async commit(name: string) {
|
|
453
453
|
if (name == null || typeof name !== 'string' || name.length === 0) {
|
|
454
454
|
throw new InvalidParametersError(
|
|
455
|
-
'Transaction commit attempted without a name.'
|
|
455
|
+
'Transaction commit attempted without a name.',
|
|
456
456
|
);
|
|
457
457
|
}
|
|
458
458
|
if (this.store.transactionsStarted === 0) {
|
|
@@ -476,7 +476,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
476
476
|
|
|
477
477
|
public async deleteEntityByID(
|
|
478
478
|
guid: string,
|
|
479
|
-
className?: EntityConstructor | string | null
|
|
479
|
+
className?: EntityConstructor | string | null,
|
|
480
480
|
) {
|
|
481
481
|
let EntityClass: EntityConstructor;
|
|
482
482
|
if (typeof className === 'string' || className == null) {
|
|
@@ -490,47 +490,47 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
490
490
|
try {
|
|
491
491
|
this.queryRun(
|
|
492
492
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
493
|
-
`${this.prefix}entities_${etype}
|
|
493
|
+
`${this.prefix}entities_${etype}`,
|
|
494
494
|
)} WHERE "guid"=@guid;`,
|
|
495
495
|
{
|
|
496
496
|
etypes: [etype],
|
|
497
497
|
params: {
|
|
498
498
|
guid,
|
|
499
499
|
},
|
|
500
|
-
}
|
|
500
|
+
},
|
|
501
501
|
);
|
|
502
502
|
this.queryRun(
|
|
503
503
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
504
|
-
`${this.prefix}data_${etype}
|
|
504
|
+
`${this.prefix}data_${etype}`,
|
|
505
505
|
)} WHERE "guid"=@guid;`,
|
|
506
506
|
{
|
|
507
507
|
etypes: [etype],
|
|
508
508
|
params: {
|
|
509
509
|
guid,
|
|
510
510
|
},
|
|
511
|
-
}
|
|
511
|
+
},
|
|
512
512
|
);
|
|
513
513
|
this.queryRun(
|
|
514
514
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
515
|
-
`${this.prefix}comparisons_${etype}
|
|
515
|
+
`${this.prefix}comparisons_${etype}`,
|
|
516
516
|
)} WHERE "guid"=@guid;`,
|
|
517
517
|
{
|
|
518
518
|
etypes: [etype],
|
|
519
519
|
params: {
|
|
520
520
|
guid,
|
|
521
521
|
},
|
|
522
|
-
}
|
|
522
|
+
},
|
|
523
523
|
);
|
|
524
524
|
this.queryRun(
|
|
525
525
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
526
|
-
`${this.prefix}references_${etype}
|
|
526
|
+
`${this.prefix}references_${etype}`,
|
|
527
527
|
)} WHERE "guid"=@guid;`,
|
|
528
528
|
{
|
|
529
529
|
etypes: [etype],
|
|
530
530
|
params: {
|
|
531
531
|
guid,
|
|
532
532
|
},
|
|
533
|
-
}
|
|
533
|
+
},
|
|
534
534
|
);
|
|
535
535
|
await this.commit('nymph-delete');
|
|
536
536
|
// Remove any cached versions of this entity.
|
|
@@ -551,13 +551,13 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
551
551
|
await this.startTransaction('nymph-delete-uid');
|
|
552
552
|
this.queryRun(
|
|
553
553
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
554
|
-
`${this.prefix}uids
|
|
554
|
+
`${this.prefix}uids`,
|
|
555
555
|
)} WHERE "name"=@name;`,
|
|
556
556
|
{
|
|
557
557
|
params: {
|
|
558
558
|
name,
|
|
559
559
|
},
|
|
560
|
-
}
|
|
560
|
+
},
|
|
561
561
|
);
|
|
562
562
|
await this.commit('nymph-delete-uid');
|
|
563
563
|
return true;
|
|
@@ -579,8 +579,8 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
579
579
|
// Export UIDs.
|
|
580
580
|
let uids: IterableIterator<any> = this.queryIter(
|
|
581
581
|
`SELECT * FROM ${SQLite3Driver.escape(
|
|
582
|
-
`${this.prefix}uids
|
|
583
|
-
)} ORDER BY "name"
|
|
582
|
+
`${this.prefix}uids`,
|
|
583
|
+
)} ORDER BY "name";`,
|
|
584
584
|
);
|
|
585
585
|
for (const uid of uids) {
|
|
586
586
|
writeLine(`<${uid.name}>[${uid.cur_uid}]`);
|
|
@@ -594,7 +594,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
594
594
|
|
|
595
595
|
// Get the etypes.
|
|
596
596
|
const tables: IterableIterator<any> = this.queryIter(
|
|
597
|
-
"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"
|
|
597
|
+
"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;",
|
|
598
598
|
);
|
|
599
599
|
const etypes = [];
|
|
600
600
|
for (const table of tables) {
|
|
@@ -607,12 +607,12 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
607
607
|
// Export entities.
|
|
608
608
|
const dataIterator: IterableIterator<any> = this.queryIter(
|
|
609
609
|
`SELECT e.*, d."name" AS "dname", d."value" AS "dvalue", c."string", c."number" FROM ${SQLite3Driver.escape(
|
|
610
|
-
`${this.prefix}entities_${etype}
|
|
610
|
+
`${this.prefix}entities_${etype}`,
|
|
611
611
|
)} e LEFT JOIN ${SQLite3Driver.escape(
|
|
612
|
-
`${this.prefix}data_${etype}
|
|
612
|
+
`${this.prefix}data_${etype}`,
|
|
613
613
|
)} d USING ("guid") INNER JOIN ${SQLite3Driver.escape(
|
|
614
|
-
`${this.prefix}comparisons_${etype}
|
|
615
|
-
)} c USING ("guid", "name") ORDER BY e."guid"
|
|
614
|
+
`${this.prefix}comparisons_${etype}`,
|
|
615
|
+
)} c USING ("guid", "name") ORDER BY e."guid";`,
|
|
616
616
|
)[Symbol.iterator]();
|
|
617
617
|
let datum = dataIterator.next();
|
|
618
618
|
while (!datum.done) {
|
|
@@ -664,7 +664,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
664
664
|
params: { [k: string]: any } = {},
|
|
665
665
|
subquery = false,
|
|
666
666
|
tableSuffix = '',
|
|
667
|
-
etypes: string[] = []
|
|
667
|
+
etypes: string[] = [],
|
|
668
668
|
) {
|
|
669
669
|
if (typeof options.class?.alterOptions === 'function') {
|
|
670
670
|
options = options.class.alterOptions(options);
|
|
@@ -1368,7 +1368,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1368
1368
|
params,
|
|
1369
1369
|
true,
|
|
1370
1370
|
tableSuffix,
|
|
1371
|
-
etypes
|
|
1371
|
+
etypes,
|
|
1372
1372
|
);
|
|
1373
1373
|
if (curQuery) {
|
|
1374
1374
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
@@ -1383,7 +1383,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1383
1383
|
case '!qref':
|
|
1384
1384
|
const [qrefOptions, ...qrefSelectors] = curValue[1] as [
|
|
1385
1385
|
Options,
|
|
1386
|
-
...FormattedSelector[]
|
|
1386
|
+
...FormattedSelector[],
|
|
1387
1387
|
];
|
|
1388
1388
|
const QrefEntityClass = qrefOptions.class as EntityConstructor;
|
|
1389
1389
|
etypes.push(QrefEntityClass.ETYPE);
|
|
@@ -1395,7 +1395,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1395
1395
|
params,
|
|
1396
1396
|
false,
|
|
1397
1397
|
makeTableSuffix(),
|
|
1398
|
-
etypes
|
|
1398
|
+
etypes,
|
|
1399
1399
|
);
|
|
1400
1400
|
if (curQuery) {
|
|
1401
1401
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
@@ -1416,7 +1416,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1416
1416
|
}
|
|
1417
1417
|
}
|
|
1418
1418
|
return curQuery;
|
|
1419
|
-
}
|
|
1419
|
+
},
|
|
1420
1420
|
);
|
|
1421
1421
|
|
|
1422
1422
|
let sortBy: string;
|
|
@@ -1465,21 +1465,21 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1465
1465
|
query = `SELECT COUNT("guid") AS "count" FROM (
|
|
1466
1466
|
SELECT "guid"
|
|
1467
1467
|
FROM ${SQLite3Driver.escape(
|
|
1468
|
-
this.prefix + 'entities_' + etype
|
|
1468
|
+
this.prefix + 'entities_' + etype,
|
|
1469
1469
|
)} ${ieTable}
|
|
1470
1470
|
WHERE (${whereClause})${limit}${offset}
|
|
1471
1471
|
)`;
|
|
1472
1472
|
} else {
|
|
1473
1473
|
query = `SELECT COUNT("guid") AS "count"
|
|
1474
1474
|
FROM ${SQLite3Driver.escape(
|
|
1475
|
-
this.prefix + 'entities_' + etype
|
|
1475
|
+
this.prefix + 'entities_' + etype,
|
|
1476
1476
|
)} ${ieTable}
|
|
1477
1477
|
WHERE (${whereClause})`;
|
|
1478
1478
|
}
|
|
1479
1479
|
} else if (options.return === 'guid') {
|
|
1480
1480
|
query = `SELECT "guid"
|
|
1481
1481
|
FROM ${SQLite3Driver.escape(
|
|
1482
|
-
this.prefix + 'entities_' + etype
|
|
1482
|
+
this.prefix + 'entities_' + etype,
|
|
1483
1483
|
)} ${ieTable}
|
|
1484
1484
|
${sortJoin}
|
|
1485
1485
|
WHERE (${whereClause})
|
|
@@ -1495,19 +1495,19 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1495
1495
|
${cTable}."string",
|
|
1496
1496
|
${cTable}."number"
|
|
1497
1497
|
FROM ${SQLite3Driver.escape(
|
|
1498
|
-
this.prefix + 'entities_' + etype
|
|
1498
|
+
this.prefix + 'entities_' + etype,
|
|
1499
1499
|
)} ${eTable}
|
|
1500
1500
|
LEFT JOIN ${SQLite3Driver.escape(
|
|
1501
|
-
this.prefix + 'data_' + etype
|
|
1501
|
+
this.prefix + 'data_' + etype,
|
|
1502
1502
|
)} ${dTable} USING ("guid")
|
|
1503
1503
|
INNER JOIN ${SQLite3Driver.escape(
|
|
1504
|
-
this.prefix + 'comparisons_' + etype
|
|
1504
|
+
this.prefix + 'comparisons_' + etype,
|
|
1505
1505
|
)} ${cTable} USING ("guid", "name")
|
|
1506
1506
|
${sortJoin}
|
|
1507
1507
|
INNER JOIN (
|
|
1508
1508
|
SELECT "guid"
|
|
1509
1509
|
FROM ${SQLite3Driver.escape(
|
|
1510
|
-
this.prefix + 'entities_' + etype
|
|
1510
|
+
this.prefix + 'entities_' + etype,
|
|
1511
1511
|
)} ${ieTable}
|
|
1512
1512
|
${sortJoin}
|
|
1513
1513
|
WHERE (${whereClause})
|
|
@@ -1533,19 +1533,19 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1533
1533
|
query = `SELECT COUNT("guid") AS "count" FROM (
|
|
1534
1534
|
SELECT "guid"
|
|
1535
1535
|
FROM ${SQLite3Driver.escape(
|
|
1536
|
-
this.prefix + 'entities_' + etype
|
|
1536
|
+
this.prefix + 'entities_' + etype,
|
|
1537
1537
|
)} ${ieTable}${limit}${offset}
|
|
1538
1538
|
)`;
|
|
1539
1539
|
} else {
|
|
1540
1540
|
query = `SELECT COUNT("guid") AS "count"
|
|
1541
1541
|
FROM ${SQLite3Driver.escape(
|
|
1542
|
-
this.prefix + 'entities_' + etype
|
|
1542
|
+
this.prefix + 'entities_' + etype,
|
|
1543
1543
|
)} ${ieTable}`;
|
|
1544
1544
|
}
|
|
1545
1545
|
} else if (options.return === 'guid') {
|
|
1546
1546
|
query = `SELECT "guid"
|
|
1547
1547
|
FROM ${SQLite3Driver.escape(
|
|
1548
|
-
this.prefix + 'entities_' + etype
|
|
1548
|
+
this.prefix + 'entities_' + etype,
|
|
1549
1549
|
)} ${ieTable}
|
|
1550
1550
|
${sortJoin}
|
|
1551
1551
|
ORDER BY ${sortByInner}, "guid"${limit}${offset}`;
|
|
@@ -1561,19 +1561,19 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1561
1561
|
${cTable}."string",
|
|
1562
1562
|
${cTable}."number"
|
|
1563
1563
|
FROM ${SQLite3Driver.escape(
|
|
1564
|
-
this.prefix + 'entities_' + etype
|
|
1564
|
+
this.prefix + 'entities_' + etype,
|
|
1565
1565
|
)} ${eTable}
|
|
1566
1566
|
LEFT JOIN ${SQLite3Driver.escape(
|
|
1567
|
-
this.prefix + 'data_' + etype
|
|
1567
|
+
this.prefix + 'data_' + etype,
|
|
1568
1568
|
)} ${dTable} USING ("guid")
|
|
1569
1569
|
INNER JOIN ${SQLite3Driver.escape(
|
|
1570
|
-
this.prefix + 'comparisons_' + etype
|
|
1570
|
+
this.prefix + 'comparisons_' + etype,
|
|
1571
1571
|
)} c USING ("guid", "name")
|
|
1572
1572
|
${sortJoin}
|
|
1573
1573
|
INNER JOIN (
|
|
1574
1574
|
SELECT "guid"
|
|
1575
1575
|
FROM ${SQLite3Driver.escape(
|
|
1576
|
-
this.prefix + 'entities_' + etype
|
|
1576
|
+
this.prefix + 'entities_' + etype,
|
|
1577
1577
|
)} ${ieTable}
|
|
1578
1578
|
${sortJoin}
|
|
1579
1579
|
ORDER BY ${sortByInner}${limit}${offset}
|
|
@@ -1590,13 +1590,13 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1590
1590
|
${cTable}."string",
|
|
1591
1591
|
${cTable}."number"
|
|
1592
1592
|
FROM ${SQLite3Driver.escape(
|
|
1593
|
-
this.prefix + 'entities_' + etype
|
|
1593
|
+
this.prefix + 'entities_' + etype,
|
|
1594
1594
|
)} ${eTable}
|
|
1595
1595
|
LEFT JOIN ${SQLite3Driver.escape(
|
|
1596
|
-
this.prefix + 'data_' + etype
|
|
1596
|
+
this.prefix + 'data_' + etype,
|
|
1597
1597
|
)} ${dTable} USING ("guid")
|
|
1598
1598
|
INNER JOIN ${SQLite3Driver.escape(
|
|
1599
|
-
this.prefix + 'comparisons_' + etype
|
|
1599
|
+
this.prefix + 'comparisons_' + etype,
|
|
1600
1600
|
)} ${cTable} USING ("guid", "name")
|
|
1601
1601
|
${sortJoin}
|
|
1602
1602
|
ORDER BY ${sortBy}, ${eTable}."guid"`;
|
|
@@ -1619,14 +1619,14 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1619
1619
|
protected performQuery(
|
|
1620
1620
|
options: Options,
|
|
1621
1621
|
formattedSelectors: FormattedSelector[],
|
|
1622
|
-
etype: string
|
|
1622
|
+
etype: string,
|
|
1623
1623
|
): {
|
|
1624
1624
|
result: any;
|
|
1625
1625
|
} {
|
|
1626
1626
|
const { query, params, etypes } = this.makeEntityQuery(
|
|
1627
1627
|
options,
|
|
1628
1628
|
formattedSelectors,
|
|
1629
|
-
etype
|
|
1629
|
+
etype,
|
|
1630
1630
|
);
|
|
1631
1631
|
const result = this.queryIter(query, { etypes, params })[Symbol.iterator]();
|
|
1632
1632
|
return {
|
|
@@ -1675,7 +1675,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1675
1675
|
: row.value === 'S'
|
|
1676
1676
|
? JSON.stringify(row.string)
|
|
1677
1677
|
: row.value,
|
|
1678
|
-
})
|
|
1678
|
+
}),
|
|
1679
1679
|
);
|
|
1680
1680
|
const value = process();
|
|
1681
1681
|
if (value instanceof Error) {
|
|
@@ -1690,13 +1690,13 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1690
1690
|
}
|
|
1691
1691
|
const result: any = this.queryGet(
|
|
1692
1692
|
`SELECT "cur_uid" FROM ${SQLite3Driver.escape(
|
|
1693
|
-
`${this.prefix}uids
|
|
1693
|
+
`${this.prefix}uids`,
|
|
1694
1694
|
)} WHERE "name"=@name;`,
|
|
1695
1695
|
{
|
|
1696
1696
|
params: {
|
|
1697
1697
|
name: name,
|
|
1698
1698
|
},
|
|
1699
|
-
}
|
|
1699
|
+
},
|
|
1700
1700
|
);
|
|
1701
1701
|
return (result?.cur_uid as number | null) ?? null;
|
|
1702
1702
|
}
|
|
@@ -1708,51 +1708,51 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1708
1708
|
async (guid, tags, sdata, etype) => {
|
|
1709
1709
|
this.queryRun(
|
|
1710
1710
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
1711
|
-
`${this.prefix}entities_${etype}
|
|
1711
|
+
`${this.prefix}entities_${etype}`,
|
|
1712
1712
|
)} WHERE "guid"=@guid;`,
|
|
1713
1713
|
{
|
|
1714
1714
|
etypes: [etype],
|
|
1715
1715
|
params: {
|
|
1716
1716
|
guid,
|
|
1717
1717
|
},
|
|
1718
|
-
}
|
|
1718
|
+
},
|
|
1719
1719
|
);
|
|
1720
1720
|
this.queryRun(
|
|
1721
1721
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
1722
|
-
`${this.prefix}data_${etype}
|
|
1722
|
+
`${this.prefix}data_${etype}`,
|
|
1723
1723
|
)} WHERE "guid"=@guid;`,
|
|
1724
1724
|
{
|
|
1725
1725
|
etypes: [etype],
|
|
1726
1726
|
params: {
|
|
1727
1727
|
guid,
|
|
1728
1728
|
},
|
|
1729
|
-
}
|
|
1729
|
+
},
|
|
1730
1730
|
);
|
|
1731
1731
|
this.queryRun(
|
|
1732
1732
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
1733
|
-
`${this.prefix}comparisons_${etype}
|
|
1733
|
+
`${this.prefix}comparisons_${etype}`,
|
|
1734
1734
|
)} WHERE "guid"=@guid;`,
|
|
1735
1735
|
{
|
|
1736
1736
|
etypes: [etype],
|
|
1737
1737
|
params: {
|
|
1738
1738
|
guid,
|
|
1739
1739
|
},
|
|
1740
|
-
}
|
|
1740
|
+
},
|
|
1741
1741
|
);
|
|
1742
1742
|
this.queryRun(
|
|
1743
1743
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
1744
|
-
`${this.prefix}references_${etype}
|
|
1744
|
+
`${this.prefix}references_${etype}`,
|
|
1745
1745
|
)} WHERE "guid"=@guid;`,
|
|
1746
1746
|
{
|
|
1747
1747
|
etypes: [etype],
|
|
1748
1748
|
params: {
|
|
1749
1749
|
guid,
|
|
1750
1750
|
},
|
|
1751
|
-
}
|
|
1751
|
+
},
|
|
1752
1752
|
);
|
|
1753
1753
|
this.queryRun(
|
|
1754
1754
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
1755
|
-
`${this.prefix}entities_${etype}
|
|
1755
|
+
`${this.prefix}entities_${etype}`,
|
|
1756
1756
|
)} ("guid", "tags", "cdate", "mdate") VALUES (@guid, @tags, @cdate, @mdate);`,
|
|
1757
1757
|
{
|
|
1758
1758
|
etypes: [etype],
|
|
@@ -1762,7 +1762,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1762
1762
|
cdate: Number(JSON.parse(sdata.cdate)),
|
|
1763
1763
|
mdate: Number(JSON.parse(sdata.mdate)),
|
|
1764
1764
|
},
|
|
1765
|
-
}
|
|
1765
|
+
},
|
|
1766
1766
|
);
|
|
1767
1767
|
delete sdata.cdate;
|
|
1768
1768
|
delete sdata.mdate;
|
|
@@ -1780,7 +1780,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1780
1780
|
: value;
|
|
1781
1781
|
this.queryRun(
|
|
1782
1782
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
1783
|
-
`${this.prefix}data_${etype}
|
|
1783
|
+
`${this.prefix}data_${etype}`,
|
|
1784
1784
|
)} ("guid", "name", "value") VALUES (@guid, @name, @storageValue);`,
|
|
1785
1785
|
{
|
|
1786
1786
|
etypes: [etype],
|
|
@@ -1789,11 +1789,11 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1789
1789
|
name,
|
|
1790
1790
|
storageValue,
|
|
1791
1791
|
},
|
|
1792
|
-
}
|
|
1792
|
+
},
|
|
1793
1793
|
);
|
|
1794
1794
|
this.queryRun(
|
|
1795
1795
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
1796
|
-
`${this.prefix}comparisons_${etype}
|
|
1796
|
+
`${this.prefix}comparisons_${etype}`,
|
|
1797
1797
|
)} ("guid", "name", "truthy", "string", "number") VALUES (@guid, @name, @truthy, @string, @number);`,
|
|
1798
1798
|
{
|
|
1799
1799
|
etypes: [etype],
|
|
@@ -1804,13 +1804,13 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1804
1804
|
string: `${uvalue}`,
|
|
1805
1805
|
number: Number(uvalue),
|
|
1806
1806
|
},
|
|
1807
|
-
}
|
|
1807
|
+
},
|
|
1808
1808
|
);
|
|
1809
1809
|
const references = this.findReferences(value);
|
|
1810
1810
|
for (const reference of references) {
|
|
1811
1811
|
this.queryRun(
|
|
1812
1812
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
1813
|
-
`${this.prefix}references_${etype}
|
|
1813
|
+
`${this.prefix}references_${etype}`,
|
|
1814
1814
|
)} ("guid", "name", "reference") VALUES (@guid, @name, @reference);`,
|
|
1815
1815
|
{
|
|
1816
1816
|
etypes: [etype],
|
|
@@ -1819,7 +1819,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1819
1819
|
name,
|
|
1820
1820
|
reference,
|
|
1821
1821
|
},
|
|
1822
|
-
}
|
|
1822
|
+
},
|
|
1823
1823
|
);
|
|
1824
1824
|
}
|
|
1825
1825
|
}
|
|
@@ -1827,24 +1827,24 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1827
1827
|
async (name, curUid) => {
|
|
1828
1828
|
this.queryRun(
|
|
1829
1829
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
1830
|
-
`${this.prefix}uids
|
|
1830
|
+
`${this.prefix}uids`,
|
|
1831
1831
|
)} WHERE "name"=@name;`,
|
|
1832
1832
|
{
|
|
1833
1833
|
params: {
|
|
1834
1834
|
name,
|
|
1835
1835
|
},
|
|
1836
|
-
}
|
|
1836
|
+
},
|
|
1837
1837
|
);
|
|
1838
1838
|
this.queryRun(
|
|
1839
1839
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
1840
|
-
`${this.prefix}uids
|
|
1840
|
+
`${this.prefix}uids`,
|
|
1841
1841
|
)} ("name", "cur_uid") VALUES (@name, @curUid);`,
|
|
1842
1842
|
{
|
|
1843
1843
|
params: {
|
|
1844
1844
|
name,
|
|
1845
1845
|
curUid,
|
|
1846
1846
|
},
|
|
1847
|
-
}
|
|
1847
|
+
},
|
|
1848
1848
|
);
|
|
1849
1849
|
},
|
|
1850
1850
|
async () => {
|
|
@@ -1852,7 +1852,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1852
1852
|
},
|
|
1853
1853
|
async () => {
|
|
1854
1854
|
await this.commit('nymph-import');
|
|
1855
|
-
}
|
|
1855
|
+
},
|
|
1856
1856
|
);
|
|
1857
1857
|
} catch (e: any) {
|
|
1858
1858
|
await this.rollback('nymph-import');
|
|
@@ -1870,40 +1870,40 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1870
1870
|
(
|
|
1871
1871
|
this.queryGet(
|
|
1872
1872
|
`SELECT "cur_uid" FROM ${SQLite3Driver.escape(
|
|
1873
|
-
`${this.prefix}uids
|
|
1873
|
+
`${this.prefix}uids`,
|
|
1874
1874
|
)} WHERE "name"=@name;`,
|
|
1875
1875
|
{
|
|
1876
1876
|
params: {
|
|
1877
1877
|
name,
|
|
1878
1878
|
},
|
|
1879
|
-
}
|
|
1879
|
+
},
|
|
1880
1880
|
) as any
|
|
1881
1881
|
)?.cur_uid ?? null;
|
|
1882
1882
|
if (curUid == null) {
|
|
1883
1883
|
curUid = 1;
|
|
1884
1884
|
this.queryRun(
|
|
1885
1885
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
1886
|
-
`${this.prefix}uids
|
|
1886
|
+
`${this.prefix}uids`,
|
|
1887
1887
|
)} ("name", "cur_uid") VALUES (@name, @curUid);`,
|
|
1888
1888
|
{
|
|
1889
1889
|
params: {
|
|
1890
1890
|
name,
|
|
1891
1891
|
curUid,
|
|
1892
1892
|
},
|
|
1893
|
-
}
|
|
1893
|
+
},
|
|
1894
1894
|
);
|
|
1895
1895
|
} else {
|
|
1896
1896
|
curUid++;
|
|
1897
1897
|
this.queryRun(
|
|
1898
1898
|
`UPDATE ${SQLite3Driver.escape(
|
|
1899
|
-
`${this.prefix}uids
|
|
1899
|
+
`${this.prefix}uids`,
|
|
1900
1900
|
)} SET "cur_uid"=@curUid WHERE "name"=@name;`,
|
|
1901
1901
|
{
|
|
1902
1902
|
params: {
|
|
1903
1903
|
curUid,
|
|
1904
1904
|
name,
|
|
1905
1905
|
},
|
|
1906
|
-
}
|
|
1906
|
+
},
|
|
1907
1907
|
);
|
|
1908
1908
|
}
|
|
1909
1909
|
await this.commit('nymph-newuid');
|
|
@@ -1921,14 +1921,14 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1921
1921
|
await this.startTransaction('nymph-rename-uid');
|
|
1922
1922
|
this.queryRun(
|
|
1923
1923
|
`UPDATE ${SQLite3Driver.escape(
|
|
1924
|
-
`${this.prefix}uids
|
|
1924
|
+
`${this.prefix}uids`,
|
|
1925
1925
|
)} SET "name"=@newName WHERE "name"=@oldName;`,
|
|
1926
1926
|
{
|
|
1927
1927
|
params: {
|
|
1928
1928
|
newName,
|
|
1929
1929
|
oldName,
|
|
1930
1930
|
},
|
|
1931
|
-
}
|
|
1931
|
+
},
|
|
1932
1932
|
);
|
|
1933
1933
|
await this.commit('nymph-rename-uid');
|
|
1934
1934
|
return true;
|
|
@@ -1937,7 +1937,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1937
1937
|
public async rollback(name: string) {
|
|
1938
1938
|
if (name == null || typeof name !== 'string' || name.length === 0) {
|
|
1939
1939
|
throw new InvalidParametersError(
|
|
1940
|
-
'Transaction rollback attempted without a name.'
|
|
1940
|
+
'Transaction rollback attempted without a name.',
|
|
1941
1941
|
);
|
|
1942
1942
|
}
|
|
1943
1943
|
if (this.store.transactionsStarted === 0) {
|
|
@@ -1964,7 +1964,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1964
1964
|
guid: string,
|
|
1965
1965
|
data: EntityData,
|
|
1966
1966
|
sdata: SerializedEntityData,
|
|
1967
|
-
etype: string
|
|
1967
|
+
etype: string,
|
|
1968
1968
|
) => {
|
|
1969
1969
|
const runInsertQuery = (name: string, value: any, svalue: string) => {
|
|
1970
1970
|
if (value === undefined) {
|
|
@@ -1978,7 +1978,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1978
1978
|
: svalue;
|
|
1979
1979
|
this.queryRun(
|
|
1980
1980
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
1981
|
-
`${this.prefix}data_${etype}
|
|
1981
|
+
`${this.prefix}data_${etype}`,
|
|
1982
1982
|
)} ("guid", "name", "value") VALUES (@guid, @name, @storageValue);`,
|
|
1983
1983
|
{
|
|
1984
1984
|
etypes: [etype],
|
|
@@ -1987,11 +1987,11 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1987
1987
|
name,
|
|
1988
1988
|
storageValue,
|
|
1989
1989
|
},
|
|
1990
|
-
}
|
|
1990
|
+
},
|
|
1991
1991
|
);
|
|
1992
1992
|
this.queryRun(
|
|
1993
1993
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
1994
|
-
`${this.prefix}comparisons_${etype}
|
|
1994
|
+
`${this.prefix}comparisons_${etype}`,
|
|
1995
1995
|
)} ("guid", "name", "truthy", "string", "number") VALUES (@guid, @name, @truthy, @string, @number);`,
|
|
1996
1996
|
{
|
|
1997
1997
|
etypes: [etype],
|
|
@@ -2002,13 +2002,13 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
2002
2002
|
string: `${value}`,
|
|
2003
2003
|
number: Number(value),
|
|
2004
2004
|
},
|
|
2005
|
-
}
|
|
2005
|
+
},
|
|
2006
2006
|
);
|
|
2007
2007
|
const references = this.findReferences(svalue);
|
|
2008
2008
|
for (const reference of references) {
|
|
2009
2009
|
this.queryRun(
|
|
2010
2010
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
2011
|
-
`${this.prefix}references_${etype}
|
|
2011
|
+
`${this.prefix}references_${etype}`,
|
|
2012
2012
|
)} ("guid", "name", "reference") VALUES (@guid, @name, @reference);`,
|
|
2013
2013
|
{
|
|
2014
2014
|
etypes: [etype],
|
|
@@ -2017,7 +2017,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
2017
2017
|
name,
|
|
2018
2018
|
reference,
|
|
2019
2019
|
},
|
|
2020
|
-
}
|
|
2020
|
+
},
|
|
2021
2021
|
);
|
|
2022
2022
|
}
|
|
2023
2023
|
};
|
|
@@ -2040,7 +2040,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
2040
2040
|
}
|
|
2041
2041
|
this.queryRun(
|
|
2042
2042
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
2043
|
-
`${this.prefix}entities_${etype}
|
|
2043
|
+
`${this.prefix}entities_${etype}`,
|
|
2044
2044
|
)} ("guid", "tags", "cdate", "mdate") VALUES (@guid, @tags, @cdate, @cdate);`,
|
|
2045
2045
|
{
|
|
2046
2046
|
etypes: [etype],
|
|
@@ -2049,7 +2049,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
2049
2049
|
tags: ',' + tags.join(',') + ',',
|
|
2050
2050
|
cdate,
|
|
2051
2051
|
},
|
|
2052
|
-
}
|
|
2052
|
+
},
|
|
2053
2053
|
);
|
|
2054
2054
|
insertData(guid, data, sdata, etype);
|
|
2055
2055
|
return true;
|
|
@@ -2063,7 +2063,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
2063
2063
|
}
|
|
2064
2064
|
const info = this.queryRun(
|
|
2065
2065
|
`UPDATE ${SQLite3Driver.escape(
|
|
2066
|
-
`${this.prefix}entities_${etype}
|
|
2066
|
+
`${this.prefix}entities_${etype}`,
|
|
2067
2067
|
)} SET "tags"=@tags, "mdate"=@mdate WHERE "guid"=@guid AND "mdate" <= @emdate;`,
|
|
2068
2068
|
{
|
|
2069
2069
|
etypes: [etype],
|
|
@@ -2073,42 +2073,42 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
2073
2073
|
guid,
|
|
2074
2074
|
emdate: Number(entity.mdate),
|
|
2075
2075
|
},
|
|
2076
|
-
}
|
|
2076
|
+
},
|
|
2077
2077
|
);
|
|
2078
2078
|
let success = false;
|
|
2079
2079
|
if (info.changes === 1) {
|
|
2080
2080
|
this.queryRun(
|
|
2081
2081
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
2082
|
-
`${this.prefix}data_${etype}
|
|
2082
|
+
`${this.prefix}data_${etype}`,
|
|
2083
2083
|
)} WHERE "guid"=@guid;`,
|
|
2084
2084
|
{
|
|
2085
2085
|
etypes: [etype],
|
|
2086
2086
|
params: {
|
|
2087
2087
|
guid,
|
|
2088
2088
|
},
|
|
2089
|
-
}
|
|
2089
|
+
},
|
|
2090
2090
|
);
|
|
2091
2091
|
this.queryRun(
|
|
2092
2092
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
2093
|
-
`${this.prefix}comparisons_${etype}
|
|
2093
|
+
`${this.prefix}comparisons_${etype}`,
|
|
2094
2094
|
)} WHERE "guid"=@guid;`,
|
|
2095
2095
|
{
|
|
2096
2096
|
etypes: [etype],
|
|
2097
2097
|
params: {
|
|
2098
2098
|
guid,
|
|
2099
2099
|
},
|
|
2100
|
-
}
|
|
2100
|
+
},
|
|
2101
2101
|
);
|
|
2102
2102
|
this.queryRun(
|
|
2103
2103
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
2104
|
-
`${this.prefix}references_${etype}
|
|
2104
|
+
`${this.prefix}references_${etype}`,
|
|
2105
2105
|
)} WHERE "guid"=@guid;`,
|
|
2106
2106
|
{
|
|
2107
2107
|
etypes: [etype],
|
|
2108
2108
|
params: {
|
|
2109
2109
|
guid,
|
|
2110
2110
|
},
|
|
2111
|
-
}
|
|
2111
|
+
},
|
|
2112
2112
|
);
|
|
2113
2113
|
insertData(guid, data, sdata, etype);
|
|
2114
2114
|
success = true;
|
|
@@ -2125,7 +2125,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
2125
2125
|
await this.rollback('nymph-save');
|
|
2126
2126
|
}
|
|
2127
2127
|
return success;
|
|
2128
|
-
}
|
|
2128
|
+
},
|
|
2129
2129
|
);
|
|
2130
2130
|
} catch (e: any) {
|
|
2131
2131
|
await this.rollback('nymph-save');
|
|
@@ -2140,24 +2140,24 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
2140
2140
|
await this.startTransaction('nymph-set-uid');
|
|
2141
2141
|
this.queryRun(
|
|
2142
2142
|
`DELETE FROM ${SQLite3Driver.escape(
|
|
2143
|
-
`${this.prefix}uids
|
|
2143
|
+
`${this.prefix}uids`,
|
|
2144
2144
|
)} WHERE "name"=@name;`,
|
|
2145
2145
|
{
|
|
2146
2146
|
params: {
|
|
2147
2147
|
name,
|
|
2148
2148
|
},
|
|
2149
|
-
}
|
|
2149
|
+
},
|
|
2150
2150
|
);
|
|
2151
2151
|
this.queryRun(
|
|
2152
2152
|
`INSERT INTO ${SQLite3Driver.escape(
|
|
2153
|
-
`${this.prefix}uids
|
|
2153
|
+
`${this.prefix}uids`,
|
|
2154
2154
|
)} ("name", "cur_uid") VALUES (@name, @curUid);`,
|
|
2155
2155
|
{
|
|
2156
2156
|
params: {
|
|
2157
2157
|
name,
|
|
2158
2158
|
curUid,
|
|
2159
2159
|
},
|
|
2160
|
-
}
|
|
2160
|
+
},
|
|
2161
2161
|
);
|
|
2162
2162
|
await this.commit('nymph-set-uid');
|
|
2163
2163
|
return true;
|
|
@@ -2166,7 +2166,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
2166
2166
|
public async startTransaction(name: string) {
|
|
2167
2167
|
if (name == null || typeof name !== 'string' || name.length === 0) {
|
|
2168
2168
|
throw new InvalidParametersError(
|
|
2169
|
-
'Transaction start attempted without a name.'
|
|
2169
|
+
'Transaction start attempted without a name.',
|
|
2170
2170
|
);
|
|
2171
2171
|
}
|
|
2172
2172
|
if (!this.config.explicitWrite && !this.store.linkWrite) {
|