@nymphjs/driver-sqlite3 1.0.0-beta.12 → 1.0.0-beta.121

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.
@@ -1,33 +1,95 @@
1
1
  import SQLite3 from 'better-sqlite3';
2
- import { NymphDriver, EntityConstructor, EntityInterface, FormattedSelector, Options, Selector } from '@nymphjs/nymph';
3
- import { SQLite3DriverConfig } from './conf';
2
+ import { NymphDriver, type EntityConstructor, type EntityObjectType, type EntityInterface, type EntityInstanceType, type SerializedEntityData, type FormattedSelector, type Options, type Selector } from '@nymphjs/nymph';
3
+ import { SQLite3DriverConfig } from './conf/index.js';
4
4
  declare class InternalStore {
5
5
  link: SQLite3.Database;
6
+ linkWrite?: SQLite3.Database;
6
7
  connected: boolean;
7
8
  transactionsStarted: number;
8
9
  constructor(link: SQLite3.Database);
9
10
  }
11
+ /**
12
+ * The SQLite3 Nymph database driver.
13
+ */
10
14
  export default class SQLite3Driver extends NymphDriver {
11
15
  config: SQLite3DriverConfig;
12
16
  protected prefix: string;
13
17
  protected store: InternalStore;
14
18
  static escape(input: string): string;
19
+ static escapeValue(input: string): string;
15
20
  constructor(config: Partial<SQLite3DriverConfig>, store?: InternalStore);
21
+ /**
22
+ * This is used internally by Nymph. Don't call it yourself.
23
+ *
24
+ * @returns A clone of this instance.
25
+ */
16
26
  clone(): SQLite3Driver;
27
+ /**
28
+ * Connect to the SQLite3 database.
29
+ *
30
+ * @returns Whether this instance is connected to a SQLite3 database.
31
+ */
17
32
  connect(): Promise<boolean>;
33
+ private _connect;
34
+ /**
35
+ * Disconnect from the SQLite3 database.
36
+ *
37
+ * @returns Whether this instance is connected to a SQLite3 database.
38
+ */
18
39
  disconnect(): Promise<false>;
19
40
  inTransaction(): Promise<boolean>;
41
+ /**
42
+ * Check connection status.
43
+ *
44
+ * @returns Whether this instance is connected to a SQLite3 database.
45
+ */
20
46
  isConnected(): boolean;
21
- private checkReadOnlyMode;
47
+ private createEntitiesTable;
48
+ private addTilmeldColumnsAndIndexes;
49
+ private createEntitiesTilmeldIndexes;
50
+ private createDataTable;
51
+ private createReferencesTable;
52
+ private createTokensTable;
53
+ private createUniquesTable;
54
+ /**
55
+ * Create entity tables in the database.
56
+ *
57
+ * @param etype The entity type to create a table for. If this is blank, the default tables are created.
58
+ */
22
59
  private createTables;
23
60
  private query;
24
- private queryIter;
61
+ private queryArray;
25
62
  private queryGet;
26
63
  private queryRun;
27
64
  commit(name: string): Promise<boolean>;
28
65
  deleteEntityByID(guid: string, className?: EntityConstructor | string | null): Promise<boolean>;
29
66
  deleteUID(name: string): Promise<boolean>;
30
- protected exportEntities(writeLine: (line: string) => void): Promise<void>;
67
+ getIndexes(etype: string): Promise<{
68
+ scope: 'data' | 'references' | 'tokens';
69
+ name: string;
70
+ property: string;
71
+ }[]>;
72
+ addIndex(etype: string, definition: {
73
+ scope: 'data' | 'references' | 'tokens';
74
+ name: string;
75
+ property: string;
76
+ }): Promise<boolean>;
77
+ deleteIndex(etype: string, scope: 'data' | 'references' | 'tokens', name: string): Promise<boolean>;
78
+ getEtypes(): Promise<string[]>;
79
+ exportDataIterator(): AsyncGenerator<{
80
+ type: 'comment' | 'uid' | 'entity';
81
+ content: string;
82
+ }, void, false | undefined>;
83
+ /**
84
+ * Generate the SQLite3 query.
85
+ * @param options The options array.
86
+ * @param formattedSelectors The formatted selector array.
87
+ * @param etype
88
+ * @param count Used to track internal params.
89
+ * @param params Used to store internal params.
90
+ * @param subquery Whether only a subquery should be returned.
91
+ * @returns The SQL query.
92
+ */
31
93
  private makeEntityQuery;
32
94
  protected performQuery(options: Options, formattedSelectors: FormattedSelector[], etype: string): {
33
95
  result: any;
@@ -38,21 +100,49 @@ export default class SQLite3Driver extends NymphDriver {
38
100
  getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
39
101
  return: 'guid';
40
102
  }, ...selectors: Selector[]): Promise<string[]>;
41
- getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<ReturnType<T['factorySync']>[]>;
42
- protected getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
43
- return: 'count';
44
- }, ...selectors: Selector[]): number;
45
- protected getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
46
- return: 'guid';
47
- }, ...selectors: Selector[]): string[];
48
- protected getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): ReturnType<T['factorySync']>[];
103
+ getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
104
+ return: 'object';
105
+ }, ...selectors: Selector[]): Promise<EntityObjectType<T>[]>;
106
+ getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T>[]>;
49
107
  getUID(name: string): Promise<number | null>;
50
- import(filename: string): Promise<boolean>;
108
+ importEntity(entity: {
109
+ guid: string;
110
+ cdate: number;
111
+ mdate: number;
112
+ tags: string[];
113
+ sdata: SerializedEntityData;
114
+ etype: string;
115
+ }): Promise<void>;
116
+ importEntityTokens(entity: {
117
+ guid: string;
118
+ cdate: number;
119
+ mdate: number;
120
+ tags: string[];
121
+ sdata: SerializedEntityData;
122
+ etype: string;
123
+ }): Promise<void>;
124
+ importEntityTilmeldAC(entity: {
125
+ guid: string;
126
+ cdate: number;
127
+ mdate: number;
128
+ tags: string[];
129
+ sdata: SerializedEntityData;
130
+ etype: string;
131
+ }): Promise<void>;
132
+ private importEntityInternal;
133
+ importUID({ name, value }: {
134
+ name: string;
135
+ value: number;
136
+ }): Promise<void>;
51
137
  newUID(name: string): Promise<number>;
52
138
  renameUID(oldName: string, newName: string): Promise<boolean>;
53
139
  rollback(name: string): Promise<boolean>;
54
140
  saveEntity(entity: EntityInterface): Promise<boolean>;
55
141
  setUID(name: string, curUid: number): Promise<boolean>;
142
+ internalTransaction(name: string): Promise<void>;
56
143
  startTransaction(name: string): Promise<import("@nymphjs/nymph").Nymph>;
144
+ private removeTilmeldOldRows;
145
+ needsMigration(): Promise<'json' | 'tokens' | 'tilmeldColumns' | false>;
146
+ liveMigration(migrationType: 'tokenTables' | 'tilmeldColumns' | 'tilmeldRemoveOldRows'): Promise<void>;
57
147
  }
58
148
  export {};