@nymphjs/driver-sqlite3 1.0.0-beta.127 → 1.0.0-beta.129
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 +13 -0
- package/README.md +1 -1
- package/dist/SQLite3Driver.d.ts +6 -4
- package/dist/SQLite3Driver.js +121 -122
- package/dist/SQLite3Driver.js.map +1 -1
- package/dist/conf/defaults.js +0 -1
- package/dist/conf/defaults.js.map +1 -1
- package/dist/conf/index.d.ts +0 -4
- package/dist/conf/index.js.map +1 -1
- package/jest.config.js +1 -1
- package/package.json +6 -8
- package/src/SQLite3Driver.ts +159 -211
- package/src/conf/defaults.ts +0 -1
- package/src/conf/index.ts +0 -4
- package/tsconfig.json +2 -2
package/src/SQLite3Driver.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import type {
|
|
3
3
|
SearchTerm,
|
|
4
4
|
SearchOrTerm,
|
|
@@ -33,12 +33,12 @@ import {
|
|
|
33
33
|
} from './conf/index.js';
|
|
34
34
|
|
|
35
35
|
class InternalStore {
|
|
36
|
-
public link:
|
|
37
|
-
public linkWrite?:
|
|
36
|
+
public link: DatabaseSync;
|
|
37
|
+
public linkWrite?: DatabaseSync;
|
|
38
38
|
public connected: boolean = false;
|
|
39
39
|
public transactionsStarted = 0;
|
|
40
40
|
|
|
41
|
-
constructor(link:
|
|
41
|
+
constructor(link: DatabaseSync) {
|
|
42
42
|
this.link = link;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -106,20 +106,20 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
private _connect(write: boolean) {
|
|
109
|
-
const { filename, fileMustExist, timeout, explicitWrite, wal
|
|
109
|
+
const { filename, fileMustExist, timeout, explicitWrite, wal } =
|
|
110
110
|
this.config;
|
|
111
111
|
|
|
112
112
|
try {
|
|
113
|
-
const setOptions = (link:
|
|
113
|
+
const setOptions = (link: DatabaseSync) => {
|
|
114
114
|
// Set database and connection options.
|
|
115
115
|
if (wal) {
|
|
116
|
-
link.
|
|
116
|
+
link.exec('PRAGMA journal_mode = WAL;');
|
|
117
117
|
}
|
|
118
|
-
link.
|
|
119
|
-
link.
|
|
120
|
-
link.
|
|
118
|
+
link.exec('PRAGMA encoding = "UTF-8";');
|
|
119
|
+
link.exec('PRAGMA foreign_keys = 1;');
|
|
120
|
+
link.exec('PRAGMA case_sensitive_like = 1;');
|
|
121
121
|
for (let pragma of this.config.pragmas) {
|
|
122
|
-
link.
|
|
122
|
+
link.exec(`PRAGMA ${pragma}`);
|
|
123
123
|
}
|
|
124
124
|
// Create the preg_match and regexp functions.
|
|
125
125
|
link.function('regexp', { deterministic: true }, ((
|
|
@@ -130,38 +130,32 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
130
130
|
) => any);
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
-
let link:
|
|
133
|
+
let link: DatabaseSync;
|
|
134
134
|
try {
|
|
135
|
-
link = new
|
|
136
|
-
|
|
137
|
-
fileMustExist,
|
|
135
|
+
link = new DatabaseSync(filename, {
|
|
136
|
+
readOnly: !explicitWrite && !write,
|
|
138
137
|
timeout,
|
|
139
|
-
verbose,
|
|
140
138
|
});
|
|
141
139
|
} catch (e: any) {
|
|
142
140
|
if (
|
|
143
|
-
e.code === '
|
|
141
|
+
e.code === 'ERR_SQLITE_CANTOPEN' &&
|
|
144
142
|
!explicitWrite &&
|
|
145
143
|
!write &&
|
|
146
|
-
!
|
|
144
|
+
!fileMustExist
|
|
147
145
|
) {
|
|
148
146
|
// This happens when the file doesn't exist and we attempt to open it
|
|
149
147
|
// readonly.
|
|
150
148
|
// First open it in write mode.
|
|
151
|
-
const writeLink = new
|
|
152
|
-
|
|
153
|
-
fileMustExist,
|
|
149
|
+
const writeLink = new DatabaseSync(filename, {
|
|
150
|
+
readOnly: false,
|
|
154
151
|
timeout,
|
|
155
|
-
verbose,
|
|
156
152
|
});
|
|
157
153
|
setOptions(writeLink);
|
|
158
154
|
writeLink.close();
|
|
159
155
|
// Now open in readonly.
|
|
160
|
-
link = new
|
|
161
|
-
|
|
162
|
-
fileMustExist,
|
|
156
|
+
link = new DatabaseSync(filename, {
|
|
157
|
+
readOnly: true,
|
|
163
158
|
timeout,
|
|
164
|
-
verbose,
|
|
165
159
|
});
|
|
166
160
|
} else {
|
|
167
161
|
throw e;
|
|
@@ -377,55 +371,36 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
377
371
|
);
|
|
378
372
|
this.queryRun(
|
|
379
373
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
380
|
-
`${this.prefix}data_${etype}
|
|
381
|
-
)} ON ${SQLite3Driver.escape(`${this.prefix}data_${etype}`)} ("guid");`,
|
|
374
|
+
`${this.prefix}data_${etype}_id_name_guid`,
|
|
375
|
+
)} ON ${SQLite3Driver.escape(`${this.prefix}data_${etype}`)} ("name", "guid");`,
|
|
382
376
|
);
|
|
383
377
|
this.queryRun(
|
|
384
378
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
385
|
-
`${this.prefix}data_${etype}
|
|
379
|
+
`${this.prefix}data_${etype}_id_name_string_guid`,
|
|
386
380
|
)} ON ${SQLite3Driver.escape(
|
|
387
381
|
`${this.prefix}data_${etype}`,
|
|
388
|
-
)} ("
|
|
382
|
+
)} ("name", "string", "guid");`,
|
|
389
383
|
);
|
|
390
384
|
this.queryRun(
|
|
391
385
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
392
|
-
`${this.prefix}data_${etype}
|
|
393
|
-
)} ON ${SQLite3Driver.escape(`${this.prefix}data_${etype}`)} ("name");`,
|
|
394
|
-
);
|
|
395
|
-
this.queryRun(
|
|
396
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
397
|
-
`${this.prefix}data_${etype}_id_name_string`,
|
|
398
|
-
)} ON ${SQLite3Driver.escape(
|
|
399
|
-
`${this.prefix}data_${etype}`,
|
|
400
|
-
)} ("name", "string");`,
|
|
401
|
-
);
|
|
402
|
-
this.queryRun(
|
|
403
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
404
|
-
`${this.prefix}data_${etype}_id_name_number`,
|
|
405
|
-
)} ON ${SQLite3Driver.escape(
|
|
406
|
-
`${this.prefix}data_${etype}`,
|
|
407
|
-
)} ("name", "number");`,
|
|
408
|
-
);
|
|
409
|
-
this.queryRun(
|
|
410
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
411
|
-
`${this.prefix}data_${etype}_id_guid_name_number`,
|
|
386
|
+
`${this.prefix}data_${etype}_id_name_number_guid`,
|
|
412
387
|
)} ON ${SQLite3Driver.escape(
|
|
413
388
|
`${this.prefix}data_${etype}`,
|
|
414
|
-
)} ("
|
|
389
|
+
)} ("name", "number", "guid");`,
|
|
415
390
|
);
|
|
416
391
|
this.queryRun(
|
|
417
392
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
418
|
-
`${this.prefix}data_${etype}
|
|
393
|
+
`${this.prefix}data_${etype}_id_name_truthy_guid`,
|
|
419
394
|
)} ON ${SQLite3Driver.escape(
|
|
420
395
|
`${this.prefix}data_${etype}`,
|
|
421
|
-
)} ("name", "truthy");`,
|
|
396
|
+
)} ("name", "truthy", "guid");`,
|
|
422
397
|
);
|
|
423
398
|
this.queryRun(
|
|
424
399
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
425
|
-
`${this.prefix}data_${etype}
|
|
400
|
+
`${this.prefix}data_${etype}_id_name_json_guid`,
|
|
426
401
|
)} ON ${SQLite3Driver.escape(
|
|
427
402
|
`${this.prefix}data_${etype}`,
|
|
428
|
-
)} ("
|
|
403
|
+
)} ("name", "json", "guid")`,
|
|
429
404
|
);
|
|
430
405
|
}
|
|
431
406
|
|
|
@@ -440,59 +415,10 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
440
415
|
);
|
|
441
416
|
this.queryRun(
|
|
442
417
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
443
|
-
`${this.prefix}references_${etype}
|
|
444
|
-
)} ON ${SQLite3Driver.escape(
|
|
445
|
-
`${this.prefix}references_${etype}`,
|
|
446
|
-
)} ("guid");`,
|
|
447
|
-
);
|
|
448
|
-
this.queryRun(
|
|
449
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
450
|
-
`${this.prefix}references_${etype}_id_name`,
|
|
451
|
-
)} ON ${SQLite3Driver.escape(
|
|
452
|
-
`${this.prefix}references_${etype}`,
|
|
453
|
-
)} ("name");`,
|
|
454
|
-
);
|
|
455
|
-
this.queryRun(
|
|
456
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
457
|
-
`${this.prefix}references_${etype}_id_name_reference`,
|
|
458
|
-
)} ON ${SQLite3Driver.escape(
|
|
459
|
-
`${this.prefix}references_${etype}`,
|
|
460
|
-
)} ("name", "reference");`,
|
|
461
|
-
);
|
|
462
|
-
this.queryRun(
|
|
463
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
464
|
-
`${this.prefix}references_${etype}_id_reference`,
|
|
465
|
-
)} ON ${SQLite3Driver.escape(
|
|
466
|
-
`${this.prefix}references_${etype}`,
|
|
467
|
-
)} ("reference");`,
|
|
468
|
-
);
|
|
469
|
-
this.queryRun(
|
|
470
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
471
|
-
`${this.prefix}references_${etype}_id_guid_name`,
|
|
472
|
-
)} ON ${SQLite3Driver.escape(
|
|
473
|
-
`${this.prefix}references_${etype}`,
|
|
474
|
-
)} ("guid", "name");`,
|
|
475
|
-
);
|
|
476
|
-
this.queryRun(
|
|
477
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
478
|
-
`${this.prefix}references_${etype}_id_guid_name_reference`,
|
|
479
|
-
)} ON ${SQLite3Driver.escape(
|
|
480
|
-
`${this.prefix}references_${etype}`,
|
|
481
|
-
)} ("guid", "name", "reference");`,
|
|
482
|
-
);
|
|
483
|
-
this.queryRun(
|
|
484
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
485
|
-
`${this.prefix}references_${etype}_id_reference_name_guid`,
|
|
486
|
-
)} ON ${SQLite3Driver.escape(
|
|
487
|
-
`${this.prefix}references_${etype}`,
|
|
488
|
-
)} ("reference", "name", "guid");`,
|
|
489
|
-
);
|
|
490
|
-
this.queryRun(
|
|
491
|
-
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
492
|
-
`${this.prefix}references_${etype}_id_reference_guid_name`,
|
|
418
|
+
`${this.prefix}references_${etype}_id_name_reference_guid`,
|
|
493
419
|
)} ON ${SQLite3Driver.escape(
|
|
494
420
|
`${this.prefix}references_${etype}`,
|
|
495
|
-
)} ("
|
|
421
|
+
)} ("name", "reference", "guid");`,
|
|
496
422
|
);
|
|
497
423
|
}
|
|
498
424
|
|
|
@@ -507,10 +433,10 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
507
433
|
);
|
|
508
434
|
this.queryRun(
|
|
509
435
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
510
|
-
`${this.prefix}tokens_${etype}
|
|
436
|
+
`${this.prefix}tokens_${etype}_id_name_token_guid`,
|
|
511
437
|
)} ON ${SQLite3Driver.escape(
|
|
512
438
|
`${this.prefix}tokens_${etype}`,
|
|
513
|
-
)} ("name", "token");`,
|
|
439
|
+
)} ("name", "token", "guid");`,
|
|
514
440
|
);
|
|
515
441
|
}
|
|
516
442
|
|
|
@@ -568,7 +494,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
568
494
|
const errorCode = e?.code;
|
|
569
495
|
const errorMsg = e?.message;
|
|
570
496
|
if (
|
|
571
|
-
errorCode === '
|
|
497
|
+
errorCode === 'ERR_SQLITE_ERROR' &&
|
|
572
498
|
errorMsg.match(/^no such table: /) &&
|
|
573
499
|
this.createTables()
|
|
574
500
|
) {
|
|
@@ -585,7 +511,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
585
511
|
);
|
|
586
512
|
}
|
|
587
513
|
} else if (
|
|
588
|
-
errorCode === '
|
|
514
|
+
errorCode === 'ERR_SQLITE_ERROR' &&
|
|
589
515
|
errorMsg.match(/^UNIQUE constraint failed: /)
|
|
590
516
|
) {
|
|
591
517
|
throw new EntityUniqueConstraintError(`Unique constraint violation.`);
|
|
@@ -781,13 +707,13 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
781
707
|
}[] = [];
|
|
782
708
|
|
|
783
709
|
for (let [scope, suffix] of [
|
|
784
|
-
['data', '
|
|
710
|
+
['data', '_string_guid'],
|
|
785
711
|
['references', '_reference_guid'],
|
|
786
|
-
['tokens', '
|
|
712
|
+
['tokens', '_token_guid'],
|
|
787
713
|
] as (
|
|
788
|
-
| ['data', '
|
|
714
|
+
| ['data', '_string_guid']
|
|
789
715
|
| ['references', '_reference_guid']
|
|
790
|
-
| ['tokens', '
|
|
716
|
+
| ['tokens', '_token_guid']
|
|
791
717
|
)[]) {
|
|
792
718
|
const indexDefinitions: IterableIterator<any> = this.queryArray(
|
|
793
719
|
`SELECT "name", "sql" FROM "sqlite_master" WHERE "type"='index' AND "name" LIKE @pattern;`,
|
|
@@ -828,31 +754,31 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
828
754
|
if (definition.scope === 'data') {
|
|
829
755
|
this.queryRun(
|
|
830
756
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
831
|
-
`${this.prefix}data_${etype}_id_custom_${definition.name}
|
|
757
|
+
`${this.prefix}data_${etype}_id_custom_${definition.name}_string_guid`,
|
|
832
758
|
)} ON ${SQLite3Driver.escape(
|
|
833
759
|
`${this.prefix}data_${etype}`,
|
|
834
|
-
)} ("
|
|
760
|
+
)} ("string", "guid") WHERE "name"=${SQLite3Driver.escapeValue(definition.property)};`,
|
|
835
761
|
);
|
|
836
762
|
this.queryRun(
|
|
837
763
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
838
|
-
`${this.prefix}data_${etype}_id_custom_${definition.name}
|
|
764
|
+
`${this.prefix}data_${etype}_id_custom_${definition.name}_number_guid`,
|
|
839
765
|
)} ON ${SQLite3Driver.escape(
|
|
840
766
|
`${this.prefix}data_${etype}`,
|
|
841
|
-
)} ("
|
|
767
|
+
)} ("number", "guid") WHERE "name"=${SQLite3Driver.escapeValue(definition.property)};`,
|
|
842
768
|
);
|
|
843
769
|
this.queryRun(
|
|
844
770
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
845
|
-
`${this.prefix}data_${etype}_id_custom_${definition.name}
|
|
771
|
+
`${this.prefix}data_${etype}_id_custom_${definition.name}_truthy_guid`,
|
|
846
772
|
)} ON ${SQLite3Driver.escape(
|
|
847
773
|
`${this.prefix}data_${etype}`,
|
|
848
|
-
)} ("
|
|
774
|
+
)} ("truthy", "guid") WHERE "name"=${SQLite3Driver.escapeValue(definition.property)};`,
|
|
849
775
|
);
|
|
850
776
|
this.queryRun(
|
|
851
777
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
852
|
-
`${this.prefix}data_${etype}_id_custom_${definition.name}
|
|
778
|
+
`${this.prefix}data_${etype}_id_custom_${definition.name}_json_guid`,
|
|
853
779
|
)} ON ${SQLite3Driver.escape(
|
|
854
780
|
`${this.prefix}data_${etype}`,
|
|
855
|
-
)} ("
|
|
781
|
+
)} ("json", "guid") WHERE "name"=${SQLite3Driver.escapeValue(definition.property)};`,
|
|
856
782
|
);
|
|
857
783
|
} else if (definition.scope === 'references') {
|
|
858
784
|
this.queryRun(
|
|
@@ -865,10 +791,10 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
865
791
|
} else if (definition.scope === 'tokens') {
|
|
866
792
|
this.queryRun(
|
|
867
793
|
`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(
|
|
868
|
-
`${this.prefix}tokens_${etype}_id_custom_${definition.name}
|
|
794
|
+
`${this.prefix}tokens_${etype}_id_custom_${definition.name}_token_guid`,
|
|
869
795
|
)} ON ${SQLite3Driver.escape(
|
|
870
796
|
`${this.prefix}tokens_${etype}`,
|
|
871
|
-
)} ("token", "
|
|
797
|
+
)} ("token", "guid") WHERE "name"=${SQLite3Driver.escapeValue(definition.property)};`,
|
|
872
798
|
);
|
|
873
799
|
}
|
|
874
800
|
return true;
|
|
@@ -883,22 +809,22 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
883
809
|
if (scope === 'data') {
|
|
884
810
|
this.queryRun(
|
|
885
811
|
`DROP INDEX IF EXISTS ${SQLite3Driver.escape(
|
|
886
|
-
`${this.prefix}data_${etype}_id_custom_${name}
|
|
812
|
+
`${this.prefix}data_${etype}_id_custom_${name}_string_guid`,
|
|
887
813
|
)};`,
|
|
888
814
|
);
|
|
889
815
|
this.queryRun(
|
|
890
816
|
`DROP INDEX IF EXISTS ${SQLite3Driver.escape(
|
|
891
|
-
`${this.prefix}data_${etype}_id_custom_${name}
|
|
817
|
+
`${this.prefix}data_${etype}_id_custom_${name}_number_guid`,
|
|
892
818
|
)};`,
|
|
893
819
|
);
|
|
894
820
|
this.queryRun(
|
|
895
821
|
`DROP INDEX IF EXISTS ${SQLite3Driver.escape(
|
|
896
|
-
`${this.prefix}data_${etype}_id_custom_${name}
|
|
822
|
+
`${this.prefix}data_${etype}_id_custom_${name}_truthy_guid`,
|
|
897
823
|
)};`,
|
|
898
824
|
);
|
|
899
825
|
this.queryRun(
|
|
900
826
|
`DROP INDEX IF EXISTS ${SQLite3Driver.escape(
|
|
901
|
-
`${this.prefix}data_${etype}_id_custom_${name}
|
|
827
|
+
`${this.prefix}data_${etype}_id_custom_${name}_json_guid`,
|
|
902
828
|
)};`,
|
|
903
829
|
);
|
|
904
830
|
} else if (scope === 'references') {
|
|
@@ -910,7 +836,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
910
836
|
} else if (scope === 'tokens') {
|
|
911
837
|
this.queryRun(
|
|
912
838
|
`DROP INDEX IF EXISTS ${SQLite3Driver.escape(
|
|
913
|
-
`${this.prefix}tokens_${etype}_id_custom_${name}
|
|
839
|
+
`${this.prefix}tokens_${etype}_id_custom_${name}_token_guid`,
|
|
914
840
|
)};`,
|
|
915
841
|
);
|
|
916
842
|
}
|
|
@@ -919,7 +845,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
919
845
|
|
|
920
846
|
public async getEtypes() {
|
|
921
847
|
const tables: IterableIterator<any> = this.queryArray(
|
|
922
|
-
|
|
848
|
+
`SELECT "name" FROM "sqlite_master" WHERE "type"='table' AND "name" LIKE @prefix;`,
|
|
923
849
|
{
|
|
924
850
|
params: {
|
|
925
851
|
prefix: this.prefix + 'entities_' + '%',
|
|
@@ -1000,85 +926,107 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
1000
926
|
|
|
1001
927
|
for (const etype of etypes) {
|
|
1002
928
|
// Export entities.
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
}
|
|
929
|
+
const entityIterator = this.exportEntityInternal(etype);
|
|
930
|
+
for await (let content of entityIterator) {
|
|
931
|
+
yield { type: 'entity', content };
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
public async exportEntity(etype: string, guid: string): Promise<string> {
|
|
937
|
+
const entityIterator = this.exportEntityInternal(etype, guid);
|
|
938
|
+
let exportContent = '';
|
|
939
|
+
for await (let content of entityIterator) {
|
|
940
|
+
exportContent += content;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
return exportContent;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
private async *exportEntityInternal(
|
|
947
|
+
etype: string,
|
|
948
|
+
guid?: string,
|
|
949
|
+
): AsyncGenerator<string, void, false | undefined> {
|
|
950
|
+
// Export entities.
|
|
951
|
+
const dataIterator: IterableIterator<any> = this.queryArray(
|
|
952
|
+
`SELECT e."guid", e."tags", e."cdate", e."mdate", e."user", e."group", e."acUser", e."acGroup", e."acOther", e."acRead", e."acWrite", e."acFull", d."name", d."value", json(d."json") as "json", d."string", d."number" FROM ${SQLite3Driver.escape(
|
|
953
|
+
`${this.prefix}entities_${etype}`,
|
|
954
|
+
)} e LEFT JOIN ${SQLite3Driver.escape(
|
|
955
|
+
`${this.prefix}data_${etype}`,
|
|
956
|
+
)} d USING ("guid")${guid == null ? '' : ` WHERE e."guid"=@guid`} ORDER BY e."guid";`,
|
|
957
|
+
guid == null ? undefined : { params: { guid } },
|
|
958
|
+
)[Symbol.iterator]();
|
|
959
|
+
let datum = dataIterator.next();
|
|
960
|
+
while (!datum.done) {
|
|
961
|
+
const guid = datum.value.guid;
|
|
962
|
+
const tags = datum.value.tags.slice(1, -1);
|
|
963
|
+
const cdate = datum.value.cdate;
|
|
964
|
+
const mdate = datum.value.mdate;
|
|
965
|
+
const user = datum.value.user;
|
|
966
|
+
const group = datum.value.group;
|
|
967
|
+
const acUser = datum.value.acUser;
|
|
968
|
+
const acGroup = datum.value.acGroup;
|
|
969
|
+
const acOther = datum.value.acOther;
|
|
970
|
+
const acRead = datum.value.acRead?.slice(1, -1).split(',');
|
|
971
|
+
const acWrite = datum.value.acWrite?.slice(1, -1).split(',');
|
|
972
|
+
const acFull = datum.value.acFull?.slice(1, -1).split(',');
|
|
973
|
+
let currentEntityExport: string[] = [];
|
|
974
|
+
currentEntityExport.push(`{${guid}}<${etype}>[${tags}]`);
|
|
975
|
+
currentEntityExport.push(`\tcdate=${JSON.stringify(cdate)}`);
|
|
976
|
+
currentEntityExport.push(`\tmdate=${JSON.stringify(mdate)}`);
|
|
977
|
+
if (this.nymph.tilmeld != null) {
|
|
978
|
+
if (user != null) {
|
|
979
|
+
currentEntityExport.push(
|
|
980
|
+
`\tuser=${JSON.stringify(['nymph_entity_reference', user, 'User'])}`,
|
|
981
|
+
);
|
|
1057
982
|
}
|
|
1058
|
-
if (
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
const value =
|
|
1063
|
-
datum.value.value === 'N'
|
|
1064
|
-
? JSON.stringify(datum.value.number)
|
|
1065
|
-
: datum.value.value === 'S'
|
|
1066
|
-
? JSON.stringify(datum.value.string)
|
|
1067
|
-
: datum.value.value === 'J'
|
|
1068
|
-
? datum.value.json
|
|
1069
|
-
: datum.value.value;
|
|
1070
|
-
currentEntityExport.push(`\t${datum.value.name}=${value}`);
|
|
1071
|
-
datum = dataIterator.next();
|
|
1072
|
-
} while (!datum.done && datum.value.guid === guid);
|
|
1073
|
-
} else {
|
|
1074
|
-
// Make sure that datum is incremented :)
|
|
1075
|
-
datum = dataIterator.next();
|
|
983
|
+
if (group != null) {
|
|
984
|
+
currentEntityExport.push(
|
|
985
|
+
`\tgroup=${JSON.stringify(['nymph_entity_reference', group, 'Group'])}`,
|
|
986
|
+
);
|
|
1076
987
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
if (yield { type: 'entity', content: currentEntityExport.join('\n') }) {
|
|
1080
|
-
return;
|
|
988
|
+
if (acUser != null) {
|
|
989
|
+
currentEntityExport.push(`\tacUser=${JSON.stringify(acUser)}`);
|
|
1081
990
|
}
|
|
991
|
+
if (acGroup != null) {
|
|
992
|
+
currentEntityExport.push(`\tacGroup=${JSON.stringify(acGroup)}`);
|
|
993
|
+
}
|
|
994
|
+
if (acOther != null) {
|
|
995
|
+
currentEntityExport.push(`\tacOther=${JSON.stringify(acOther)}`);
|
|
996
|
+
}
|
|
997
|
+
if (acRead != null) {
|
|
998
|
+
currentEntityExport.push(`\tacRead=${JSON.stringify(acRead)}`);
|
|
999
|
+
}
|
|
1000
|
+
if (acWrite != null) {
|
|
1001
|
+
currentEntityExport.push(`\tacWrite=${JSON.stringify(acWrite)}`);
|
|
1002
|
+
}
|
|
1003
|
+
if (acFull != null) {
|
|
1004
|
+
currentEntityExport.push(`\tacFull=${JSON.stringify(acFull)}`);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
if (datum.value.name != null) {
|
|
1008
|
+
// This do will keep going and adding the data until the
|
|
1009
|
+
// next entity is reached. datum will end on the next entity.
|
|
1010
|
+
do {
|
|
1011
|
+
const value =
|
|
1012
|
+
datum.value.value === 'N'
|
|
1013
|
+
? JSON.stringify(datum.value.number)
|
|
1014
|
+
: datum.value.value === 'S'
|
|
1015
|
+
? JSON.stringify(datum.value.string)
|
|
1016
|
+
: datum.value.value === 'J'
|
|
1017
|
+
? datum.value.json
|
|
1018
|
+
: datum.value.value;
|
|
1019
|
+
currentEntityExport.push(`\t${datum.value.name}=${value}`);
|
|
1020
|
+
datum = dataIterator.next();
|
|
1021
|
+
} while (!datum.done && datum.value.guid === guid);
|
|
1022
|
+
} else {
|
|
1023
|
+
// Make sure that datum is incremented :)
|
|
1024
|
+
datum = dataIterator.next();
|
|
1025
|
+
}
|
|
1026
|
+
currentEntityExport.push('');
|
|
1027
|
+
|
|
1028
|
+
if (yield currentEntityExport.join('\n')) {
|
|
1029
|
+
return;
|
|
1082
1030
|
}
|
|
1083
1031
|
}
|
|
1084
1032
|
}
|
|
@@ -3434,7 +3382,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
3434
3382
|
'json' | 'tokens' | 'tilmeldColumns' | false
|
|
3435
3383
|
> {
|
|
3436
3384
|
const table: any = this.queryGet(
|
|
3437
|
-
|
|
3385
|
+
`SELECT "name" FROM "sqlite_master" WHERE "type"='table' AND "name" LIKE @prefix LIMIT 1;`,
|
|
3438
3386
|
{
|
|
3439
3387
|
params: {
|
|
3440
3388
|
prefix: this.prefix + 'data_' + '%',
|
|
@@ -3443,7 +3391,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
3443
3391
|
);
|
|
3444
3392
|
if (table?.name) {
|
|
3445
3393
|
const result: any = this.queryGet(
|
|
3446
|
-
|
|
3394
|
+
`SELECT 1 AS "exists" FROM pragma_table_info(@table) WHERE "name"='json';`,
|
|
3447
3395
|
{
|
|
3448
3396
|
params: {
|
|
3449
3397
|
table: table.name,
|
|
@@ -3455,7 +3403,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
3455
3403
|
}
|
|
3456
3404
|
}
|
|
3457
3405
|
const table2: any = this.queryGet(
|
|
3458
|
-
|
|
3406
|
+
`SELECT "name" FROM "sqlite_master" WHERE "type"='table' AND "name" LIKE @tokenTable LIMIT 1;`,
|
|
3459
3407
|
{
|
|
3460
3408
|
params: {
|
|
3461
3409
|
tokenTable: this.prefix + 'tokens_' + '%',
|
|
@@ -3466,7 +3414,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
3466
3414
|
return 'tokens';
|
|
3467
3415
|
}
|
|
3468
3416
|
const table3: any = this.queryGet(
|
|
3469
|
-
|
|
3417
|
+
`SELECT "name" FROM "sqlite_master" WHERE "type"='table' AND "name" LIKE @prefix LIMIT 1;`,
|
|
3470
3418
|
{
|
|
3471
3419
|
params: {
|
|
3472
3420
|
prefix: this.prefix + 'entities_' + '%',
|
|
@@ -3475,7 +3423,7 @@ export default class SQLite3Driver extends NymphDriver {
|
|
|
3475
3423
|
);
|
|
3476
3424
|
if (table3?.name) {
|
|
3477
3425
|
const result: any = this.queryGet(
|
|
3478
|
-
|
|
3426
|
+
`SELECT 1 AS "exists" FROM pragma_table_info(@table) WHERE "name"='user';`,
|
|
3479
3427
|
{
|
|
3480
3428
|
params: {
|
|
3481
3429
|
table: table3.name,
|
package/src/conf/defaults.ts
CHANGED
package/src/conf/index.ts
CHANGED
|
@@ -59,10 +59,6 @@ export interface SQLite3DriverConfig {
|
|
|
59
59
|
* (Don't include the PRAGMA keyword, but do include the semicolon.)
|
|
60
60
|
*/
|
|
61
61
|
pragmas: string[];
|
|
62
|
-
/**
|
|
63
|
-
* Function that gets called with every SQL string executed.
|
|
64
|
-
*/
|
|
65
|
-
verbose: ((message?: any, ...additionalArgs: any[]) => void) | undefined;
|
|
66
62
|
}
|
|
67
63
|
|
|
68
64
|
import defaults from './defaults.js';
|
package/tsconfig.json
CHANGED