@nymphjs/driver-mysql 1.0.0-beta.14 → 1.0.0-beta.141

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