@nymphjs/driver-mysql 1.0.0-beta.13 → 1.0.0-beta.130

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