@twin.org/entity-storage-connector-mysql 0.0.3-next.6 → 0.0.3-next.7

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,6 @@
1
- # TWIN Entity Storage Connector MySQL
1
+ # Entity Storage Connector MySQL
2
2
 
3
- Entity Storage connector implementation using MySQL storage.
3
+ This package provides a MySQL backend for relational persistence and SQL-based access patterns. It is designed to work with the wider storage ecosystem so applications can keep behaviour consistent across connectors and environments.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,18 +8,13 @@ Entity Storage connector implementation using MySQL storage.
8
8
  npm install @twin.org/entity-storage-connector-mysql
9
9
  ```
10
10
 
11
- ## Testing
11
+ ## Docker
12
12
 
13
- The tests developed are functional tests and need an instance of MySql up and running. To run MySql locally:
13
+ To perform testing of this component it may be necessary to launch a local instance to communicate with.
14
14
 
15
- ```sh
16
- docker run -p 3400:3306 --name twin-entity-storage-mysql --hostname mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:latest
17
- ```
18
-
19
- Afterwards you can run the tests as follows:
20
-
21
- ```sh
22
- npm run test
15
+ ```shell
16
+ docker pull mysql:latest
17
+ docker run -d --name twin-entity-storage-mysql -e MYSQL_ROOT_PASSWORD=password -p 3400:3306 mysql:latest
23
18
  ```
24
19
 
25
20
  ## Examples
@@ -596,47 +596,64 @@ export class MySqlEntityStorageConnector {
596
596
  const dbValue = this.propertyToDbValue(comparator.value, type);
597
597
  values.push(dbValue);
598
598
  if (comparator.property.split(".").length > 1) {
599
- return `JSON_UNQUOTE(JSON_EXTRACT(\`${comparator.property.split(".")[0]}\`, '$.${comparator.property.split(".").slice(1).join(".")}')) = ?`;
600
- }
601
- else if (comparator.comparison === ComparisonOperator.Equals) {
602
- if (Is.object(comparator.value) || Is.array(comparator.value)) {
603
- return `JSON_CONTAINS(\`${prop}\`, ?)`;
604
- }
605
- return `\`${prop}\` = ?`;
606
- }
607
- else if (comparator.comparison === ComparisonOperator.NotEquals) {
608
- if (Is.object(comparator.value) || Is.array(comparator.value)) {
609
- return `NOT JSON_CONTAINS(\`${prop}\`, ?)`;
599
+ const rootProp = comparator.property.split(".")[0];
600
+ const nestedPath = comparator.property.split(".").slice(1).join(".");
601
+ const rootSchema = this._entitySchema.properties?.find(p => p.property === rootProp);
602
+ const isArray = rootSchema?.type === EntitySchemaPropertyType.Array;
603
+ const jsonPath = isArray ? `$[*].${nestedPath}` : `$.${nestedPath}`;
604
+ const jsonExpr = `JSON_UNQUOTE(JSON_EXTRACT(\`${rootProp}\`, '${jsonPath}'))`;
605
+ switch (comparator.comparison) {
606
+ case ComparisonOperator.Includes: {
607
+ values.pop();
608
+ values.push(`%${String(comparator.value).toLowerCase()}%`);
609
+ return `LOWER(${jsonExpr}) LIKE ?`;
610
+ }
611
+ case ComparisonOperator.NotEquals:
612
+ return `${jsonExpr} <> ?`;
613
+ case ComparisonOperator.GreaterThan:
614
+ return `${jsonExpr} > ?`;
615
+ case ComparisonOperator.LessThan:
616
+ return `${jsonExpr} < ?`;
617
+ case ComparisonOperator.GreaterThanOrEqual:
618
+ return `${jsonExpr} >= ?`;
619
+ case ComparisonOperator.LessThanOrEqual:
620
+ return `${jsonExpr} <= ?`;
621
+ default:
622
+ return `${jsonExpr} = ?`;
610
623
  }
611
- return `\`${prop}\` <> ?`;
612
- }
613
- else if (comparator.comparison === ComparisonOperator.GreaterThan) {
614
- return `\`${prop}\` > ?`;
615
- }
616
- else if (comparator.comparison === ComparisonOperator.LessThan) {
617
- return `\`${prop}\` < ?`;
618
- }
619
- else if (comparator.comparison === ComparisonOperator.GreaterThanOrEqual) {
620
- return `\`${prop}\` >= ?`;
621
624
  }
622
- else if (comparator.comparison === ComparisonOperator.LessThanOrEqual) {
623
- return `\`${prop}\` <= ?`;
624
- }
625
- else if (comparator.comparison === ComparisonOperator.Includes) {
626
- // For string fields, use LIKE for substring matching
627
- if (type === EntitySchemaPropertyType.String) {
628
- return `\`${prop}\` LIKE CONCAT('%', ?, '%')`;
629
- }
630
- // For array and object fields, use JSON_CONTAINS
631
- if (type === EntitySchemaPropertyType.Array || type === EntitySchemaPropertyType.Object) {
625
+ switch (comparator.comparison) {
626
+ case ComparisonOperator.Equals:
627
+ if (Is.object(comparator.value) || Is.array(comparator.value)) {
628
+ return `JSON_CONTAINS(\`${prop}\`, ?)`;
629
+ }
630
+ return `\`${prop}\` = ?`;
631
+ case ComparisonOperator.NotEquals:
632
+ if (Is.object(comparator.value) || Is.array(comparator.value)) {
633
+ return `NOT JSON_CONTAINS(\`${prop}\`, ?)`;
634
+ }
635
+ return `\`${prop}\` <> ?`;
636
+ case ComparisonOperator.GreaterThan:
637
+ return `\`${prop}\` > ?`;
638
+ case ComparisonOperator.LessThan:
639
+ return `\`${prop}\` < ?`;
640
+ case ComparisonOperator.GreaterThanOrEqual:
641
+ return `\`${prop}\` >= ?`;
642
+ case ComparisonOperator.LessThanOrEqual:
643
+ return `\`${prop}\` <= ?`;
644
+ case ComparisonOperator.Includes: {
645
+ if (type === EntitySchemaPropertyType.String) {
646
+ values.pop();
647
+ values.push(`%${String(comparator.value).toLowerCase()}%`);
648
+ return `LOWER(\`${prop}\`) LIKE ?`;
649
+ }
632
650
  return `JSON_CONTAINS(\`${prop}\`, ?)`;
633
651
  }
634
- // Fallback to JSON_CONTAINS for backwards compatibility
635
- return `JSON_CONTAINS(\`${prop}\`, ?)`;
652
+ default:
653
+ throw new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "comparisonNotSupported", {
654
+ comparison: comparator.comparison
655
+ });
636
656
  }
637
- throw new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "comparisonNotSupported", {
638
- comparison: comparator.comparison
639
- });
640
657
  }
641
658
  /**
642
659
  * Format a value to insert into DB.
@@ -1 +1 @@
1
- {"version":3,"file":"mysqlEntityStorageConnector.js","sourceRoot":"","sources":["../../src/mysqlEntityStorageConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,u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CACZ,OAAO,GAAG,UAAU,CAAC;gCACrB,MAAM;4BACP,KAAK,OAAO,CAAC;4BACb,KAAK,QAAQ;gCACZ,OAAO,GAAG,KAAK,CAAC;gCAChB,MAAM;4BACP,KAAK,OAAO,CAAC;4BACb,KAAK,QAAQ;gCACZ,OAAO,GAAG,QAAQ,CAAC;gCACnB,MAAM;wBACR,CAAC;wBACD,MAAM;gBACR,CAAC;YACF,CAAC;YACD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC;YAEvD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACpB,IAAI,OAAO,KAAK,UAAU,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;oBAClD,WAAW,CAAC,IAAI,CAAC,KAAK,UAAU,SAAS,CAAC,CAAC;gBAC5C,CAAC;qBAAM,CAAC;oBACP,WAAW,CAAC,IAAI,CAAC,KAAK,UAAU,IAAI,CAAC,CAAC;gBACvC,CAAC;YACF,CAAC;YACD,OAAO,KAAK,UAAU,MAAM,OAAO,GAAG,QAAQ,EAAE,CAAC;QAClD,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,oBAAoB,GACzB,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,kBAAkB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,OAAO,iBAAiB,GAAG,oBAAoB,CAAC;IACjD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ContextIdHelper, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tCoerce,\n\tComponentFactory,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tObjectHelper,\n\tSharedStore\n} from \"@twin.org/core\";\nimport {\n\tComparisonOperator,\n\ttype EntityCondition,\n\tEntitySchemaFactory,\n\tEntitySchemaHelper,\n\tEntitySchemaPropertyType,\n\ttype IComparator,\n\ttype IEntitySchema,\n\ttype IEntitySchemaProperty,\n\tLogicalOperator,\n\tSortDirection\n} from \"@twin.org/entity\";\nimport type { IEntityStorageConnector } from \"@twin.org/entity-storage-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { type Pool, type PoolOptions, createPool } from \"mysql2/promise\";\nimport type { IMySqlEntityStorageConnectorConfig } from \"./models/IMySqlEntityStorageConnectorConfig.js\";\nimport type { IMySqlEntityStorageConnectorConstructorOptions } from \"./models/IMySqlEntityStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing entity storage operations using MySql.\n */\nexport class MySqlEntityStorageConnector<T = unknown> implements IEntityStorageConnector<T> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MySqlEntityStorageConnector>();\n\n\t/**\n\t * Limit the number of entities when finding.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_LIMIT: number = 40;\n\n\t/**\n\t * Partition id field name.\n\t * @internal\n\t */\n\tprivate static readonly _PARTITION_KEY: string = \"partitionId\";\n\n\t/**\n\t * Partition id field value.\n\t * @internal\n\t */\n\tprivate static readonly _PARTITION_KEY_VALUE: string = \"root\";\n\n\t/**\n\t * The schema for the entity.\n\t * @internal\n\t */\n\tprivate readonly _entitySchema: IEntitySchema<T>;\n\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t * @internal\n\t */\n\tprivate readonly _partitionContextIds?: string[];\n\n\t/**\n\t * The configuration for the connector.\n\t * @internal\n\t */\n\tprivate readonly _config: IMySqlEntityStorageConnectorConfig;\n\n\t/**\n\t * The connection pool for MySql.\n\t * @internal\n\t */\n\tprivate _pool?: Pool;\n\n\t/**\n\t * The primary key property.\n\t * @internal\n\t */\n\tprivate readonly _primaryKeyProperty: IEntitySchemaProperty<T>;\n\n\t/**\n\t * Create a new instance of MySqlEntityStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IMySqlEntityStorageConnectorConstructorOptions) {\n\t\tGuards.object(MySqlEntityStorageConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.entitySchema),\n\t\t\toptions.entitySchema\n\t\t);\n\t\tGuards.object<IMySqlEntityStorageConnectorConfig>(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.host),\n\t\t\toptions.config.host\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.user),\n\t\t\toptions.config.user\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.password),\n\t\t\toptions.config.password\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.database),\n\t\t\toptions.config.database\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.tableName),\n\t\t\toptions.config.tableName\n\t\t);\n\n\t\tthis._entitySchema = EntitySchemaFactory.get(options.entitySchema);\n\t\tthis._partitionContextIds = options.partitionContextIds;\n\t\tthis._primaryKeyProperty = EntitySchemaHelper.getPrimaryKey(this._entitySchema);\n\n\t\tthis._config = options.config;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn MySqlEntityStorageConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the schema for the entities.\n\t * @returns The schema for the entities.\n\t */\n\tpublic getSchema(): IEntitySchema {\n\t\treturn this._entitySchema as IEntitySchema;\n\t}\n\n\t/**\n\t * Initialize the MySql environment.\n\t * @param nodeLoggingComponentType Optional type of the logging component.\n\t * @returns A promise that resolves to a boolean indicating success.\n\t */\n\tpublic async bootstrap(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\n\t\t\tconst databaseExists = await this.databaseExists();\n\t\t\tif (!databaseExists) {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"databaseCreating\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tdatabaseName: this._config.database\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tawait pool.query(`CREATE DATABASE IF NOT EXISTS \\`${this._config.database}\\``);\n\n\t\t\t\tawait this.waitForDatabaseExists();\n\t\t\t} else {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"databaseExists\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tdatabaseName: this._config.database\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst tableExists = await this.tableExists();\n\t\t\tif (!tableExists) {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"tableCreating\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\ttableName: this._config.tableName\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tawait pool.query(\n\t\t\t\t\t`CREATE TABLE IF NOT EXISTS \\`${this._config.database}\\`.\\`${this._config.tableName}\\` (${this.mapMySqlProperties()})`\n\t\t\t\t);\n\n\t\t\t\tawait this.waitForTableExists();\n\t\t\t} else {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"tableExists\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\ttableName: this._config.tableName\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"databaseCreateFailed\",\n\t\t\t\terror: BaseError.fromError(error),\n\t\t\t\tdata: {\n\t\t\t\t\tdatabaseName: this._config.database\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * The component needs to be stopped when the node is closed.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns Nothing.\n\t */\n\tpublic async stop(nodeLoggingComponentType?: string): Promise<void> {\n\t\tawait this.close();\n\t}\n\n\t/**\n\t * Get an entity from MySql.\n\t * @param id The id of the entity to get, or the index value if secondaryIndex is set.\n\t * @param secondaryIndex Get the item using a secondary index.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The object if it can be found or undefined.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\tsecondaryIndex?: keyof T,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<T | undefined> {\n\t\tGuards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\n\t\t\tconst whereClauses: string[] = [];\n\t\t\tconst values: unknown[] = [];\n\n\t\t\twhereClauses.push(`\\`${MySqlEntityStorageConnector._PARTITION_KEY}\\` = ?`);\n\t\t\tvalues.push(partitionKey ?? MySqlEntityStorageConnector._PARTITION_KEY_VALUE);\n\n\t\t\tif (secondaryIndex) {\n\t\t\t\twhereClauses.push(`\\`${String(secondaryIndex)}\\` = ?`);\n\t\t\t} else {\n\t\t\t\twhereClauses.push(`\\`${String(this._primaryKeyProperty.property)}\\` = ?`);\n\t\t\t}\n\t\t\tvalues.push(id);\n\n\t\t\tif (Is.arrayValue(conditions)) {\n\t\t\t\tfor (const condition of conditions) {\n\t\t\t\t\twhereClauses.push(`\\`${String(condition.property)}\\` = ?`);\n\t\t\t\t\tvalues.push(condition.value);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst query = `SELECT * FROM \\`${this._config.database}\\`.\\`${this._config.tableName}\\` WHERE ${whereClauses.join(\" AND \")} LIMIT 1`;\n\t\t\tconst [rows] = await pool.query(query, values);\n\n\t\t\tif (Is.array(rows) && rows.length === 1) {\n\t\t\t\tconst item = ObjectHelper.removeEmptyProperties(rows[0] as T, { removeNull: true });\n\t\t\t\tObjectHelper.propertyDelete(item, MySqlEntityStorageConnector._PARTITION_KEY);\n\t\t\t\treturn item;\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"getFailed\",\n\t\t\t\t{\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Set an entity.\n\t * @param entity The entity to set.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The id of the entity.\n\t */\n\tpublic async set(entity: T, conditions?: { property: keyof T; value: unknown }[]): Promise<void> {\n\t\tGuards.object<T>(MySqlEntityStorageConnector.CLASS_NAME, nameof(entity), entity);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tEntitySchemaHelper.validateEntity(entity, this._entitySchema);\n\n\t\tconst id = entity[this._primaryKeyProperty.property] as unknown as string;\n\n\t\ttry {\n\t\t\tif (Is.arrayValue(conditions)) {\n\t\t\t\tconst itemData = await this.get(id);\n\t\t\t\tif (Is.notEmpty(itemData) && !this.verifyConditions(conditions, itemData as T)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst finalEntity = ObjectHelper.clone(entity);\n\n\t\t\tconst props = [...(this._entitySchema.properties ?? [])];\n\t\t\tprops.unshift({\n\t\t\t\tproperty: MySqlEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\t\ttype: EntitySchemaPropertyType.String\n\t\t\t});\n\n\t\t\tObjectHelper.propertySet(\n\t\t\t\tfinalEntity,\n\t\t\t\tMySqlEntityStorageConnector._PARTITION_KEY,\n\t\t\t\tpartitionKey ?? MySqlEntityStorageConnector._PARTITION_KEY_VALUE\n\t\t\t);\n\n\t\t\tconst keys: string[] = [];\n\t\t\tconst values = [];\n\n\t\t\tfor (const prop of props) {\n\t\t\t\tif (!(Is.empty(finalEntity[prop.property]) && (prop.optional ?? false))) {\n\t\t\t\t\tkeys.push(prop.property as string);\n\t\t\t\t\tif (\n\t\t\t\t\t\tprop.type === EntitySchemaPropertyType.Object ||\n\t\t\t\t\t\tprop.type === EntitySchemaPropertyType.Array\n\t\t\t\t\t) {\n\t\t\t\t\t\tvalues.push(JSON.stringify(finalEntity[prop.property]));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalues.push(finalEntity[prop.property]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet sql = `INSERT INTO \\`${this._config.database}\\`.\\`${this._config.tableName}\\``;\n\t\t\tsql += ` (${keys.map(key => `\\`${key}\\``).join(\", \")})`;\n\t\t\tsql += ` VALUES (${values.map(() => \"?\").join(\", \")})`;\n\t\t\tsql += ` ON DUPLICATE KEY UPDATE ${keys.map(key => `\\`${key}\\` = VALUES(\\`${key}\\`)`).join(\", \")};`;\n\n\t\t\tconst pool = this.getPool();\n\t\t\tawait pool.query(sql, values);\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"setFailed\",\n\t\t\t\t{\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove the entity.\n\t * @param id The id of the entity to remove.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(\n\t\tid: string,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<void> {\n\t\tGuards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\n\t\t\tconst itemData = await this.get(id, undefined, conditions);\n\t\t\tif (Is.notEmpty(itemData)) {\n\t\t\t\tconst values: unknown[] = [];\n\t\t\t\tconst whereClauses: string[] = [];\n\n\t\t\t\twhereClauses.push(`\\`${this._primaryKeyProperty.property as string}\\` = ?`);\n\t\t\t\tvalues.push(id);\n\n\t\t\t\twhereClauses.push(`\\`${MySqlEntityStorageConnector._PARTITION_KEY}\\` = ?`);\n\t\t\t\tvalues.push(partitionKey ?? MySqlEntityStorageConnector._PARTITION_KEY_VALUE);\n\n\t\t\t\tif (Is.arrayValue(conditions)) {\n\t\t\t\t\twhereClauses.push(\n\t\t\t\t\t\t...conditions.map(condition => {\n\t\t\t\t\t\t\tvalues.push(condition.value);\n\t\t\t\t\t\t\treturn `\\`${String(condition.property)}\\` = ?`;\n\t\t\t\t\t\t})\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst query = `DELETE FROM \\`${this._config.database}\\`.\\`${this._config.tableName}\\` WHERE ${whereClauses.join(\" AND \")}`;\n\t\t\t\tawait pool.query(query, values);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"removeFailed\",\n\t\t\t\t{\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Find all the entities which match the conditions.\n\t * @param conditions The conditions to match for the entities.\n\t * @param sortProperties The optional sort order.\n\t * @param properties The optional properties to return, defaults to all.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tconditions?: EntityCondition<T>,\n\t\tsortProperties?: { property: keyof T; sortDirection: SortDirection }[],\n\t\tproperties?: (keyof T)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{ entities: Partial<T>[]; cursor?: string }> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tlet sql = \"\";\n\t\ttry {\n\t\t\tconst returnSize = limit ?? MySqlEntityStorageConnector._DEFAULT_LIMIT;\n\n\t\t\tlet orderByClause: string = \"\";\n\t\t\tif (Is.array(sortProperties)) {\n\t\t\t\tconst orderClauses: string[] = [];\n\t\t\t\tfor (const sortProperty of sortProperties) {\n\t\t\t\t\tconst direction = sortProperty.sortDirection === SortDirection.Ascending ? \"ASC\" : \"DESC\";\n\t\t\t\t\torderClauses.push(`\\`${String(sortProperty.property)}\\` ${direction}`);\n\t\t\t\t}\n\t\t\t\torderByClause = `ORDER BY ${orderClauses.join(\", \")}`;\n\t\t\t}\n\n\t\t\tconst whereClauses: string[] = [];\n\t\t\tconst values: unknown[] = [];\n\n\t\t\tconst finalConditions: EntityCondition<T> = {\n\t\t\t\tconditions: [],\n\t\t\t\tlogicalOperator: LogicalOperator.And\n\t\t\t};\n\n\t\t\tfinalConditions.conditions.push({\n\t\t\t\tproperty: MySqlEntityStorageConnector._PARTITION_KEY,\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: partitionKey ?? MySqlEntityStorageConnector._PARTITION_KEY_VALUE\n\t\t\t});\n\n\t\t\tif (!Is.empty(conditions)) {\n\t\t\t\tfinalConditions.conditions.push(conditions);\n\t\t\t}\n\n\t\t\tthis.buildQueryParameters(\"\", finalConditions, whereClauses, values);\n\n\t\t\tconst startIndex = Coerce.number(cursor) ?? 0;\n\n\t\t\tsql = `SELECT ${properties ? properties.map(p => `\\`${String(p)}\\``).join(\", \") : \"*\"} FROM \\`${this._config.database}\\`.\\`${this._config.tableName}\\``;\n\t\t\tsql += ` WHERE ${whereClauses.join(\" AND \")} ${orderByClause}`;\n\t\t\tsql += ` LIMIT ${returnSize} OFFSET ${startIndex}`;\n\n\t\t\tconst pool = this.getPool();\n\t\t\tconst [rows] = (await pool.query(sql, values)) ?? [];\n\n\t\t\tconst entities = rows as Partial<T>[];\n\t\t\tfor (let i = 0; i < entities.length; i++) {\n\t\t\t\tentities[i] = ObjectHelper.removeEmptyProperties(entities[i], { removeNull: true });\n\t\t\t\tObjectHelper.propertyDelete(entities[i], MySqlEntityStorageConnector._PARTITION_KEY);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tentities,\n\t\t\t\tcursor:\n\t\t\t\t\tIs.array(rows) && rows.length === returnSize\n\t\t\t\t\t\t? Coerce.string(startIndex + returnSize)\n\t\t\t\t\t\t: undefined\n\t\t\t};\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, \"queryFailed\", { sql }, err);\n\t\t}\n\t}\n\n\t/**\n\t * Drop the table.\n\t * @returns Nothing.\n\t */\n\tpublic async tableDrop(): Promise<void> {\n\t\ttry {\n\t\t\tif (await this.tableExists()) {\n\t\t\t\tconst pool = this.getPool();\n\t\t\t\tawait pool.query(`DROP TABLE \\`${this._config.database}\\`.\\`${this._config.tableName}\\`;`);\n\n\t\t\t\tawait this.waitForTableNotExists();\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\t}\n\n\t/**\n\t * Empty the table.\n\t * @returns Nothing.\n\t */\n\tpublic async tableEmpty(): Promise<void> {\n\t\ttry {\n\t\t\tif (await this.tableExists()) {\n\t\t\t\tconst pool = this.getPool();\n\t\t\t\tawait pool.query(\n\t\t\t\t\t`TRUNCATE TABLE \\`${this._config.database}\\`.\\`${this._config.tableName}\\`;`\n\t\t\t\t);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\t}\n\n\t/**\n\t * Check if the database exists.\n\t * @returns True if the database exists, false otherwise.\n\t */\n\tpublic async databaseExists(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\t\t\tconst [rows] = await pool.query(\"SHOW DATABASES LIKE ?;\", [this._config.database]);\n\t\t\treturn Is.arrayValue(rows);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Close the connection pool and release all connections.\n\t * Should be called when the connector is no longer needed.\n\t * @returns Nothing.\n\t */\n\tpublic async close(): Promise<void> {\n\t\tif (this._pool) {\n\t\t\tconst poolConfig = this.createPoolConfig();\n\t\t\tconst poolId = `${poolConfig.host}|${poolConfig.port}|${poolConfig.user}`;\n\n\t\t\tlet sharedPools = SharedStore.get<{ [id: string]: { pool: Pool; useCounter: number } }>(\n\t\t\t\t\"mySqlPools\"\n\t\t\t);\n\t\t\tsharedPools ??= {};\n\t\t\tif (sharedPools[poolId]) {\n\t\t\t\t// Decrease the use counter and close the pool if no longer used\n\t\t\t\tsharedPools[poolId].useCounter--;\n\t\t\t\tif (sharedPools[poolId].useCounter <= 0) {\n\t\t\t\t\tawait this._pool.end();\n\t\t\t\t\tdelete sharedPools[poolId];\n\t\t\t\t}\n\t\t\t\tSharedStore.set(\"mySqlPools\", sharedPools);\n\t\t\t}\n\n\t\t\tthis._pool = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Wait for a database to exist.\n\t * @returns Nothing.\n\t * @internal\n\t */\n\tprivate async waitForDatabaseExists(): Promise<void> {\n\t\tfor (let attempt = 0; attempt < 20; attempt++) {\n\t\t\tconst databaseExists = await this.databaseExists();\n\t\t\tif (databaseExists) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait new Promise(resolve => setTimeout(resolve, 250));\n\t\t}\n\t}\n\n\t/**\n\t * Check if the table exists.\n\t * @returns True if the table exists, false otherwise.\n\t * @internal\n\t */\n\tprivate async tableExists(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\t\t\tconst [rows] = await pool.query(\"SHOW TABLES FROM ?? LIKE ?\", [\n\t\t\t\tthis._config.database,\n\t\t\t\tthis._config.tableName\n\t\t\t]);\n\t\t\treturn Is.arrayValue(rows);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Wait for a table to exist.\n\t * @returns Nothing.\n\t * @internal\n\t */\n\tprivate async waitForTableExists(): Promise<void> {\n\t\tfor (let attempt = 0; attempt < 20; attempt++) {\n\t\t\tconst tableExists = await this.tableExists();\n\t\t\tif (tableExists) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait new Promise(resolve => setTimeout(resolve, 250));\n\t\t}\n\t}\n\n\t/**\n\t * Wait for a table to not exist.\n\t * @returns Nothing.\n\t * @internal\n\t */\n\tprivate async waitForTableNotExists(): Promise<void> {\n\t\tfor (let attempt = 0; attempt < 20; attempt++) {\n\t\t\tconst tableExists = await this.tableExists();\n\t\t\tif (!tableExists) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait new Promise(resolve => setTimeout(resolve, 250));\n\t\t}\n\t}\n\n\t/**\n\t * Get or create the connection pool.\n\t * @returns The MySql connection pool.\n\t * @internal\n\t */\n\tprivate getPool(): Pool {\n\t\tif (!this._pool) {\n\t\t\tconst poolConfig = this.createPoolConfig();\n\t\t\tconst poolId = `${poolConfig.host}|${poolConfig.port}|${poolConfig.user}`;\n\n\t\t\tlet sharedPools = SharedStore.get<{ [id: string]: { pool: Pool; useCounter: number } }>(\n\t\t\t\t\"mySqlPools\"\n\t\t\t);\n\t\t\tsharedPools ??= {};\n\n\t\t\t// If there is no pool for the id, create it\n\t\t\tif (!sharedPools[poolId]) {\n\t\t\t\tsharedPools[poolId] = {\n\t\t\t\t\tpool: createPool(poolConfig),\n\t\t\t\t\tuseCounter: 0\n\t\t\t\t};\n\t\t\t\tSharedStore.set(\"mySqlPools\", sharedPools);\n\t\t\t}\n\t\t\t// Increase the use counter and return the pool\n\t\t\tsharedPools[poolId].useCounter++;\n\t\t\tthis._pool = sharedPools[poolId].pool;\n\t\t}\n\t\treturn this._pool;\n\t}\n\n\t/**\n\t * Create the connection pool configuration.\n\t * @returns The MySql pool configuration.\n\t * @internal\n\t */\n\tprivate createPoolConfig(): PoolOptions {\n\t\tconst poolConfig = this._config.pool ?? {};\n\n\t\treturn {\n\t\t\thost: this._config.host,\n\t\t\tport: this._config.port ?? 3306,\n\t\t\tuser: this._config.user,\n\t\t\tpassword: this._config.password,\n\n\t\t\tconnectionLimit: poolConfig.connectionLimit ?? 10,\n\t\t\tmaxIdle: poolConfig.maxIdle ?? 10,\n\t\t\tidleTimeout: poolConfig.idleTimeout ?? 60000,\n\t\t\tenableKeepAlive: poolConfig.enableKeepAlive ?? true,\n\t\t\tkeepAliveInitialDelay: 0,\n\t\t\twaitForConnections: poolConfig.waitForConnections ?? true,\n\t\t\tqueueLimit: poolConfig.queueLimit ?? 0\n\t\t};\n\t}\n\n\t/**\n\t * Create an SQL condition clause.\n\t * @param objectPath The path for the nested object.\n\t * @param condition The conditions to create the query from.\n\t * @param whereClauses The where clauses to use in the query.\n\t * @param values The values to use in the query.\n\t * @internal\n\t */\n\tprivate buildQueryParameters(\n\t\tobjectPath: string,\n\t\tcondition: EntityCondition<T> | undefined,\n\t\twhereClauses: string[],\n\t\tvalues: unknown[]\n\t): void {\n\t\tif (Is.undefined(condition)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (\"conditions\" in condition) {\n\t\t\tif (condition.conditions.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst joinConditions: string[] = condition.conditions.map(c => {\n\t\t\t\tconst subWhereClauses: string[] = [];\n\t\t\t\tconst subValues: unknown[] = [];\n\t\t\t\tthis.buildQueryParameters(objectPath, c, subWhereClauses, subValues);\n\t\t\t\tvalues.push(...subValues);\n\t\t\t\treturn subWhereClauses.join(\" AND \");\n\t\t\t});\n\n\t\t\tconst logicalOperator = this.mapConditionalOperator(condition.logicalOperator);\n\t\t\tconst queryClause = joinConditions.filter(j => j.length > 0).join(` ${logicalOperator} `);\n\n\t\t\tif (queryClause.length > 0) {\n\t\t\t\twhereClauses.push(`(${queryClause})`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst schemaProp = this._entitySchema.properties?.find(p => p.property === condition.property);\n\t\tconst comparison = this.mapComparisonOperator(objectPath, condition, schemaProp?.type, values);\n\t\twhereClauses.push(comparison);\n\t}\n\n\t/**\n\t * Map the framework comparison operators to those in MySQL.\n\t * @param objectPath The prefix to use for the condition.\n\t * @param comparator The operator to map.\n\t * @param type The type of the property.\n\t * @param values The values to use in the query.\n\t * @returns The comparison expression.\n\t * @throws GeneralError if the comparison operator is not supported.\n\t * @internal\n\t */\n\tprivate mapComparisonOperator(\n\t\tobjectPath: string,\n\t\tcomparator: IComparator,\n\t\ttype: EntitySchemaPropertyType | undefined,\n\t\tvalues: unknown[]\n\t): string {\n\t\tlet prop = objectPath;\n\t\tif (prop.length > 0) {\n\t\t\tprop += \".\";\n\t\t}\n\n\t\tprop += comparator.property;\n\n\t\tif (comparator.comparison === ComparisonOperator.In) {\n\t\t\tconst inValues = Is.array(comparator.value) ? comparator.value : [comparator.value];\n\t\t\tvalues.push(...inValues.map(val => this.propertyToDbValue(val, type)));\n\t\t\tconst placeholders = inValues.map(() => \"?\").join(\", \");\n\t\t\treturn `\\`${prop}\\` IN (${placeholders})`;\n\t\t}\n\t\tconst dbValue = this.propertyToDbValue(comparator.value, type);\n\t\tvalues.push(dbValue);\n\n\t\tif (comparator.property.split(\".\").length > 1) {\n\t\t\treturn `JSON_UNQUOTE(JSON_EXTRACT(\\`${comparator.property.split(\".\")[0]}\\`, '$.${comparator.property.split(\".\").slice(1).join(\".\")}')) = ?`;\n\t\t} else if (comparator.comparison === ComparisonOperator.Equals) {\n\t\t\tif (Is.object(comparator.value) || Is.array(comparator.value)) {\n\t\t\t\treturn `JSON_CONTAINS(\\`${prop}\\`, ?)`;\n\t\t\t}\n\t\t\treturn `\\`${prop}\\` = ?`;\n\t\t} else if (comparator.comparison === ComparisonOperator.NotEquals) {\n\t\t\tif (Is.object(comparator.value) || Is.array(comparator.value)) {\n\t\t\t\treturn `NOT JSON_CONTAINS(\\`${prop}\\`, ?)`;\n\t\t\t}\n\t\t\treturn `\\`${prop}\\` <> ?`;\n\t\t} else if (comparator.comparison === ComparisonOperator.GreaterThan) {\n\t\t\treturn `\\`${prop}\\` > ?`;\n\t\t} else if (comparator.comparison === ComparisonOperator.LessThan) {\n\t\t\treturn `\\`${prop}\\` < ?`;\n\t\t} else if (comparator.comparison === ComparisonOperator.GreaterThanOrEqual) {\n\t\t\treturn `\\`${prop}\\` >= ?`;\n\t\t} else if (comparator.comparison === ComparisonOperator.LessThanOrEqual) {\n\t\t\treturn `\\`${prop}\\` <= ?`;\n\t\t} else if (comparator.comparison === ComparisonOperator.Includes) {\n\t\t\t// For string fields, use LIKE for substring matching\n\t\t\tif (type === EntitySchemaPropertyType.String) {\n\t\t\t\treturn `\\`${prop}\\` LIKE CONCAT('%', ?, '%')`;\n\t\t\t}\n\t\t\t// For array and object fields, use JSON_CONTAINS\n\t\t\tif (type === EntitySchemaPropertyType.Array || type === EntitySchemaPropertyType.Object) {\n\t\t\t\treturn `JSON_CONTAINS(\\`${prop}\\`, ?)`;\n\t\t\t}\n\t\t\t// Fallback to JSON_CONTAINS for backwards compatibility\n\t\t\treturn `JSON_CONTAINS(\\`${prop}\\`, ?)`;\n\t\t}\n\n\t\tthrow new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, \"comparisonNotSupported\", {\n\t\t\tcomparison: comparator.comparison\n\t\t});\n\t}\n\n\t/**\n\t * Format a value to insert into DB.\n\t * @param value The value to format.\n\t * @param type The type for the property.\n\t * @returns The value after conversion.\n\t * @internal\n\t */\n\tprivate propertyToDbValue(value: unknown, type?: EntitySchemaPropertyType): unknown {\n\t\tif (Is.object(value)) {\n\t\t\treturn JSON.stringify(value);\n\t\t}\n\n\t\tif (type === \"string\") {\n\t\t\treturn String(value);\n\t\t} else if (type === \"number\") {\n\t\t\treturn Number(value);\n\t\t} else if (type === \"boolean\") {\n\t\t\treturn Boolean(value);\n\t\t}\n\n\t\treturn value;\n\t}\n\n\t/**\n\t * Map the framework conditional operators to those in MySQL.\n\t * @param operator The operator to map.\n\t * @returns The conditional operator.\n\t * @throws GeneralError if the conditional operator is not supported.\n\t * @internal\n\t */\n\tprivate mapConditionalOperator(operator?: LogicalOperator): string {\n\t\tif ((operator ?? LogicalOperator.And) === LogicalOperator.And) {\n\t\t\treturn \"AND\";\n\t\t} else if (operator === LogicalOperator.Or) {\n\t\t\treturn \"OR\";\n\t\t}\n\n\t\tthrow new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, \"conditionalNotSupported\", {\n\t\t\toperator\n\t\t});\n\t}\n\n\t/**\n\t * Verify the conditions for the entity.\n\t * @param conditions The conditions to verify.\n\t * @internal\n\t */\n\tprivate verifyConditions(\n\t\tconditions: { property: keyof T; value: unknown }[],\n\t\tobj: { [key in keyof T]: unknown }\n\t): boolean {\n\t\treturn conditions.every(\n\t\t\tcondition => ObjectHelper.propertyGet(obj, condition.property as string) === condition.value\n\t\t);\n\t}\n\n\t/**\n\t * Map entity schema properties to SQL properties.\n\t * @returns The SQL properties as a string.\n\t * @throws GeneralError if the entity properties do not exist.\n\t */\n\tprivate mapMySqlProperties(): string {\n\t\tconst sqlTypeMap: { [key in EntitySchemaPropertyType]: string } = {\n\t\t\t[EntitySchemaPropertyType.String]: \"LONGTEXT\",\n\t\t\t[EntitySchemaPropertyType.Number]: \"FLOAT\",\n\t\t\t[EntitySchemaPropertyType.Integer]: \"INT\",\n\t\t\t[EntitySchemaPropertyType.Object]: \"JSON\",\n\t\t\t[EntitySchemaPropertyType.Array]: \"JSON\",\n\t\t\t[EntitySchemaPropertyType.Boolean]: \"TINYINT(1)\"\n\t\t};\n\n\t\tif (!this._entitySchema.properties) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"entitySchemaPropertiesUndefined\"\n\t\t\t);\n\t\t}\n\n\t\tconst primaryKeys: string[] = [];\n\n\t\tconst props: IEntitySchemaProperty<T>[] = [...this._entitySchema.properties];\n\n\t\tprops.unshift({\n\t\t\tproperty: MySqlEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\ttype: EntitySchemaPropertyType.String,\n\t\t\tisPrimary: true\n\t\t});\n\n\t\tconst columnDefinitions = props\n\t\t\t.map(prop => {\n\t\t\t\tlet sqlType = sqlTypeMap[prop.type] || \"TEXT\";\n\t\t\t\tif (prop.format) {\n\t\t\t\t\tswitch (prop.type) {\n\t\t\t\t\t\tcase \"string\":\n\t\t\t\t\t\t\tsqlType = \"LONGTEXT\";\n\t\t\t\t\t\t\tswitch (prop.format) {\n\t\t\t\t\t\t\t\tcase \"uuid\":\n\t\t\t\t\t\t\t\t\tsqlType = \"CHAR(36)\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"date\":\n\t\t\t\t\t\t\t\tcase \"date-time\":\n\t\t\t\t\t\t\t\t\tsqlType = \"LONGTEXT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\t\tsqlType = \"FLOAT\";\n\t\t\t\t\t\t\tswitch (prop.format) {\n\t\t\t\t\t\t\t\tcase \"float\":\n\t\t\t\t\t\t\t\t\tsqlType = \"FLOAT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"double\":\n\t\t\t\t\t\t\t\t\tsqlType = \"DOUBLE\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"integer\":\n\t\t\t\t\t\t\tsqlType = \"INT\";\n\t\t\t\t\t\t\tswitch (prop.format) {\n\t\t\t\t\t\t\t\tcase \"int8\":\n\t\t\t\t\t\t\t\tcase \"uint8\":\n\t\t\t\t\t\t\t\t\tsqlType = \"TINYINT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"int16\":\n\t\t\t\t\t\t\t\tcase \"uint16\":\n\t\t\t\t\t\t\t\t\tsqlType = \"SMALLINT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"int32\":\n\t\t\t\t\t\t\t\tcase \"uint32\":\n\t\t\t\t\t\t\t\t\tsqlType = \"INT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"int64\":\n\t\t\t\t\t\t\t\tcase \"uint64\":\n\t\t\t\t\t\t\t\t\tsqlType = \"BIGINT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst columnName = String(prop.property);\n\t\t\t\tconst nullable = prop.optional ? \" NULL\" : \" NOT NULL\";\n\n\t\t\t\tif (prop.isPrimary) {\n\t\t\t\t\tif (sqlType === \"LONGTEXT\" || sqlType === \"TEXT\") {\n\t\t\t\t\t\tprimaryKeys.push(`\\`${columnName}\\`(255)`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tprimaryKeys.push(`\\`${columnName}\\``);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn `\\`${columnName}\\` ${sqlType}${nullable}`;\n\t\t\t})\n\t\t\t.join(\", \");\n\n\t\tconst primaryKeyDefinition =\n\t\t\tprimaryKeys.length > 0 ? `, PRIMARY KEY (${primaryKeys.join(\", \")})` : \"\";\n\t\treturn columnDefinitions + primaryKeyDefinition;\n\t}\n}\n"]}
1
+ {"version":3,"file":"mysqlEntityStorageConnector.js","sourceRoot":"","sources":["../../src/mysqlEntityStorageConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACN,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,EAAE,EACF,YAAY,EACZ,WAAW,EACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,kBAAkB,EAElB,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EAIxB,eAAe,EACf,aAAa,EACb,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAA+B,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIzE;;GAEG;AACH,MAAM,OAAO,2BAA2B;IACvC;;OAEG;IACI,MAAM,CAAU,UAAU,iCAAiD;IAElF;;;OAGG;IACK,MAAM,CAAU,cAAc,GAAW,EAAE,CAAC;IAEpD;;;OAGG;IACK,MAAM,CAAU,cAAc,GAAW,aAAa,CAAC;IAE/D;;;OAGG;IACK,MAAM,CAAU,oB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C,EAAE,CAAC;QAC3E,OAAO,iBAAiB,GAAG,oBAAoB,CAAC;IACjD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ContextIdHelper, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tCoerce,\n\tComponentFactory,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tObjectHelper,\n\tSharedStore\n} from \"@twin.org/core\";\nimport {\n\tComparisonOperator,\n\ttype EntityCondition,\n\tEntitySchemaFactory,\n\tEntitySchemaHelper,\n\tEntitySchemaPropertyType,\n\ttype IComparator,\n\ttype IEntitySchema,\n\ttype IEntitySchemaProperty,\n\tLogicalOperator,\n\tSortDirection\n} from \"@twin.org/entity\";\nimport type { IEntityStorageConnector } from \"@twin.org/entity-storage-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { type Pool, type PoolOptions, createPool } from \"mysql2/promise\";\nimport type { IMySqlEntityStorageConnectorConfig } from \"./models/IMySqlEntityStorageConnectorConfig.js\";\nimport type { IMySqlEntityStorageConnectorConstructorOptions } from \"./models/IMySqlEntityStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing entity storage operations using MySql.\n */\nexport class MySqlEntityStorageConnector<T = unknown> implements IEntityStorageConnector<T> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MySqlEntityStorageConnector>();\n\n\t/**\n\t * Limit the number of entities when finding.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_LIMIT: number = 40;\n\n\t/**\n\t * Partition id field name.\n\t * @internal\n\t */\n\tprivate static readonly _PARTITION_KEY: string = \"partitionId\";\n\n\t/**\n\t * Partition id field value.\n\t * @internal\n\t */\n\tprivate static readonly _PARTITION_KEY_VALUE: string = \"root\";\n\n\t/**\n\t * The schema for the entity.\n\t * @internal\n\t */\n\tprivate readonly _entitySchema: IEntitySchema<T>;\n\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t * @internal\n\t */\n\tprivate readonly _partitionContextIds?: string[];\n\n\t/**\n\t * The configuration for the connector.\n\t * @internal\n\t */\n\tprivate readonly _config: IMySqlEntityStorageConnectorConfig;\n\n\t/**\n\t * The connection pool for MySql.\n\t * @internal\n\t */\n\tprivate _pool?: Pool;\n\n\t/**\n\t * The primary key property.\n\t * @internal\n\t */\n\tprivate readonly _primaryKeyProperty: IEntitySchemaProperty<T>;\n\n\t/**\n\t * Create a new instance of MySqlEntityStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IMySqlEntityStorageConnectorConstructorOptions) {\n\t\tGuards.object(MySqlEntityStorageConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.entitySchema),\n\t\t\toptions.entitySchema\n\t\t);\n\t\tGuards.object<IMySqlEntityStorageConnectorConfig>(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.host),\n\t\t\toptions.config.host\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.user),\n\t\t\toptions.config.user\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.password),\n\t\t\toptions.config.password\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.database),\n\t\t\toptions.config.database\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.tableName),\n\t\t\toptions.config.tableName\n\t\t);\n\n\t\tthis._entitySchema = EntitySchemaFactory.get(options.entitySchema);\n\t\tthis._partitionContextIds = options.partitionContextIds;\n\t\tthis._primaryKeyProperty = EntitySchemaHelper.getPrimaryKey(this._entitySchema);\n\n\t\tthis._config = options.config;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn MySqlEntityStorageConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the schema for the entities.\n\t * @returns The schema for the entities.\n\t */\n\tpublic getSchema(): IEntitySchema {\n\t\treturn this._entitySchema as IEntitySchema;\n\t}\n\n\t/**\n\t * Initialize the MySql environment.\n\t * @param nodeLoggingComponentType Optional type of the logging component.\n\t * @returns A promise that resolves to a boolean indicating success.\n\t */\n\tpublic async bootstrap(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\n\t\t\tconst databaseExists = await this.databaseExists();\n\t\t\tif (!databaseExists) {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"databaseCreating\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tdatabaseName: this._config.database\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tawait pool.query(`CREATE DATABASE IF NOT EXISTS \\`${this._config.database}\\``);\n\n\t\t\t\tawait this.waitForDatabaseExists();\n\t\t\t} else {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"databaseExists\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tdatabaseName: this._config.database\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst tableExists = await this.tableExists();\n\t\t\tif (!tableExists) {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"tableCreating\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\ttableName: this._config.tableName\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tawait pool.query(\n\t\t\t\t\t`CREATE TABLE IF NOT EXISTS \\`${this._config.database}\\`.\\`${this._config.tableName}\\` (${this.mapMySqlProperties()})`\n\t\t\t\t);\n\n\t\t\t\tawait this.waitForTableExists();\n\t\t\t} else {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"tableExists\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\ttableName: this._config.tableName\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: MySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"databaseCreateFailed\",\n\t\t\t\terror: BaseError.fromError(error),\n\t\t\t\tdata: {\n\t\t\t\t\tdatabaseName: this._config.database\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * The component needs to be stopped when the node is closed.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns Nothing.\n\t */\n\tpublic async stop(nodeLoggingComponentType?: string): Promise<void> {\n\t\tawait this.close();\n\t}\n\n\t/**\n\t * Get an entity from MySql.\n\t * @param id The id of the entity to get, or the index value if secondaryIndex is set.\n\t * @param secondaryIndex Get the item using a secondary index.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The object if it can be found or undefined.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\tsecondaryIndex?: keyof T,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<T | undefined> {\n\t\tGuards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\n\t\t\tconst whereClauses: string[] = [];\n\t\t\tconst values: unknown[] = [];\n\n\t\t\twhereClauses.push(`\\`${MySqlEntityStorageConnector._PARTITION_KEY}\\` = ?`);\n\t\t\tvalues.push(partitionKey ?? MySqlEntityStorageConnector._PARTITION_KEY_VALUE);\n\n\t\t\tif (secondaryIndex) {\n\t\t\t\twhereClauses.push(`\\`${String(secondaryIndex)}\\` = ?`);\n\t\t\t} else {\n\t\t\t\twhereClauses.push(`\\`${String(this._primaryKeyProperty.property)}\\` = ?`);\n\t\t\t}\n\t\t\tvalues.push(id);\n\n\t\t\tif (Is.arrayValue(conditions)) {\n\t\t\t\tfor (const condition of conditions) {\n\t\t\t\t\twhereClauses.push(`\\`${String(condition.property)}\\` = ?`);\n\t\t\t\t\tvalues.push(condition.value);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst query = `SELECT * FROM \\`${this._config.database}\\`.\\`${this._config.tableName}\\` WHERE ${whereClauses.join(\" AND \")} LIMIT 1`;\n\t\t\tconst [rows] = await pool.query(query, values);\n\n\t\t\tif (Is.array(rows) && rows.length === 1) {\n\t\t\t\tconst item = ObjectHelper.removeEmptyProperties(rows[0] as T, { removeNull: true });\n\t\t\t\tObjectHelper.propertyDelete(item, MySqlEntityStorageConnector._PARTITION_KEY);\n\t\t\t\treturn item;\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"getFailed\",\n\t\t\t\t{\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Set an entity.\n\t * @param entity The entity to set.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The id of the entity.\n\t */\n\tpublic async set(entity: T, conditions?: { property: keyof T; value: unknown }[]): Promise<void> {\n\t\tGuards.object<T>(MySqlEntityStorageConnector.CLASS_NAME, nameof(entity), entity);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tEntitySchemaHelper.validateEntity(entity, this._entitySchema);\n\n\t\tconst id = entity[this._primaryKeyProperty.property] as unknown as string;\n\n\t\ttry {\n\t\t\tif (Is.arrayValue(conditions)) {\n\t\t\t\tconst itemData = await this.get(id);\n\t\t\t\tif (Is.notEmpty(itemData) && !this.verifyConditions(conditions, itemData as T)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst finalEntity = ObjectHelper.clone(entity);\n\n\t\t\tconst props = [...(this._entitySchema.properties ?? [])];\n\t\t\tprops.unshift({\n\t\t\t\tproperty: MySqlEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\t\ttype: EntitySchemaPropertyType.String\n\t\t\t});\n\n\t\t\tObjectHelper.propertySet(\n\t\t\t\tfinalEntity,\n\t\t\t\tMySqlEntityStorageConnector._PARTITION_KEY,\n\t\t\t\tpartitionKey ?? MySqlEntityStorageConnector._PARTITION_KEY_VALUE\n\t\t\t);\n\n\t\t\tconst keys: string[] = [];\n\t\t\tconst values = [];\n\n\t\t\tfor (const prop of props) {\n\t\t\t\tif (!(Is.empty(finalEntity[prop.property]) && (prop.optional ?? false))) {\n\t\t\t\t\tkeys.push(prop.property as string);\n\t\t\t\t\tif (\n\t\t\t\t\t\tprop.type === EntitySchemaPropertyType.Object ||\n\t\t\t\t\t\tprop.type === EntitySchemaPropertyType.Array\n\t\t\t\t\t) {\n\t\t\t\t\t\tvalues.push(JSON.stringify(finalEntity[prop.property]));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalues.push(finalEntity[prop.property]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet sql = `INSERT INTO \\`${this._config.database}\\`.\\`${this._config.tableName}\\``;\n\t\t\tsql += ` (${keys.map(key => `\\`${key}\\``).join(\", \")})`;\n\t\t\tsql += ` VALUES (${values.map(() => \"?\").join(\", \")})`;\n\t\t\tsql += ` ON DUPLICATE KEY UPDATE ${keys.map(key => `\\`${key}\\` = VALUES(\\`${key}\\`)`).join(\", \")};`;\n\n\t\t\tconst pool = this.getPool();\n\t\t\tawait pool.query(sql, values);\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"setFailed\",\n\t\t\t\t{\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove the entity.\n\t * @param id The id of the entity to remove.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(\n\t\tid: string,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<void> {\n\t\tGuards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\n\t\t\tconst itemData = await this.get(id, undefined, conditions);\n\t\t\tif (Is.notEmpty(itemData)) {\n\t\t\t\tconst values: unknown[] = [];\n\t\t\t\tconst whereClauses: string[] = [];\n\n\t\t\t\twhereClauses.push(`\\`${this._primaryKeyProperty.property as string}\\` = ?`);\n\t\t\t\tvalues.push(id);\n\n\t\t\t\twhereClauses.push(`\\`${MySqlEntityStorageConnector._PARTITION_KEY}\\` = ?`);\n\t\t\t\tvalues.push(partitionKey ?? MySqlEntityStorageConnector._PARTITION_KEY_VALUE);\n\n\t\t\t\tif (Is.arrayValue(conditions)) {\n\t\t\t\t\twhereClauses.push(\n\t\t\t\t\t\t...conditions.map(condition => {\n\t\t\t\t\t\t\tvalues.push(condition.value);\n\t\t\t\t\t\t\treturn `\\`${String(condition.property)}\\` = ?`;\n\t\t\t\t\t\t})\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst query = `DELETE FROM \\`${this._config.database}\\`.\\`${this._config.tableName}\\` WHERE ${whereClauses.join(\" AND \")}`;\n\t\t\t\tawait pool.query(query, values);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"removeFailed\",\n\t\t\t\t{\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Find all the entities which match the conditions.\n\t * @param conditions The conditions to match for the entities.\n\t * @param sortProperties The optional sort order.\n\t * @param properties The optional properties to return, defaults to all.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tconditions?: EntityCondition<T>,\n\t\tsortProperties?: { property: keyof T; sortDirection: SortDirection }[],\n\t\tproperties?: (keyof T)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{ entities: Partial<T>[]; cursor?: string }> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tlet sql = \"\";\n\t\ttry {\n\t\t\tconst returnSize = limit ?? MySqlEntityStorageConnector._DEFAULT_LIMIT;\n\n\t\t\tlet orderByClause: string = \"\";\n\t\t\tif (Is.array(sortProperties)) {\n\t\t\t\tconst orderClauses: string[] = [];\n\t\t\t\tfor (const sortProperty of sortProperties) {\n\t\t\t\t\tconst direction = sortProperty.sortDirection === SortDirection.Ascending ? \"ASC\" : \"DESC\";\n\t\t\t\t\torderClauses.push(`\\`${String(sortProperty.property)}\\` ${direction}`);\n\t\t\t\t}\n\t\t\t\torderByClause = `ORDER BY ${orderClauses.join(\", \")}`;\n\t\t\t}\n\n\t\t\tconst whereClauses: string[] = [];\n\t\t\tconst values: unknown[] = [];\n\n\t\t\tconst finalConditions: EntityCondition<T> = {\n\t\t\t\tconditions: [],\n\t\t\t\tlogicalOperator: LogicalOperator.And\n\t\t\t};\n\n\t\t\tfinalConditions.conditions.push({\n\t\t\t\tproperty: MySqlEntityStorageConnector._PARTITION_KEY,\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: partitionKey ?? MySqlEntityStorageConnector._PARTITION_KEY_VALUE\n\t\t\t});\n\n\t\t\tif (!Is.empty(conditions)) {\n\t\t\t\tfinalConditions.conditions.push(conditions);\n\t\t\t}\n\n\t\t\tthis.buildQueryParameters(\"\", finalConditions, whereClauses, values);\n\n\t\t\tconst startIndex = Coerce.number(cursor) ?? 0;\n\n\t\t\tsql = `SELECT ${properties ? properties.map(p => `\\`${String(p)}\\``).join(\", \") : \"*\"} FROM \\`${this._config.database}\\`.\\`${this._config.tableName}\\``;\n\t\t\tsql += ` WHERE ${whereClauses.join(\" AND \")} ${orderByClause}`;\n\t\t\tsql += ` LIMIT ${returnSize} OFFSET ${startIndex}`;\n\n\t\t\tconst pool = this.getPool();\n\t\t\tconst [rows] = (await pool.query(sql, values)) ?? [];\n\n\t\t\tconst entities = rows as Partial<T>[];\n\t\t\tfor (let i = 0; i < entities.length; i++) {\n\t\t\t\tentities[i] = ObjectHelper.removeEmptyProperties(entities[i], { removeNull: true });\n\t\t\t\tObjectHelper.propertyDelete(entities[i], MySqlEntityStorageConnector._PARTITION_KEY);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tentities,\n\t\t\t\tcursor:\n\t\t\t\t\tIs.array(rows) && rows.length === returnSize\n\t\t\t\t\t\t? Coerce.string(startIndex + returnSize)\n\t\t\t\t\t\t: undefined\n\t\t\t};\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, \"queryFailed\", { sql }, err);\n\t\t}\n\t}\n\n\t/**\n\t * Drop the table.\n\t * @returns Nothing.\n\t */\n\tpublic async tableDrop(): Promise<void> {\n\t\ttry {\n\t\t\tif (await this.tableExists()) {\n\t\t\t\tconst pool = this.getPool();\n\t\t\t\tawait pool.query(`DROP TABLE \\`${this._config.database}\\`.\\`${this._config.tableName}\\`;`);\n\n\t\t\t\tawait this.waitForTableNotExists();\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\t}\n\n\t/**\n\t * Empty the table.\n\t * @returns Nothing.\n\t */\n\tpublic async tableEmpty(): Promise<void> {\n\t\ttry {\n\t\t\tif (await this.tableExists()) {\n\t\t\t\tconst pool = this.getPool();\n\t\t\t\tawait pool.query(\n\t\t\t\t\t`TRUNCATE TABLE \\`${this._config.database}\\`.\\`${this._config.tableName}\\`;`\n\t\t\t\t);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\t}\n\n\t/**\n\t * Check if the database exists.\n\t * @returns True if the database exists, false otherwise.\n\t */\n\tpublic async databaseExists(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\t\t\tconst [rows] = await pool.query(\"SHOW DATABASES LIKE ?;\", [this._config.database]);\n\t\t\treturn Is.arrayValue(rows);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Close the connection pool and release all connections.\n\t * Should be called when the connector is no longer needed.\n\t * @returns Nothing.\n\t */\n\tpublic async close(): Promise<void> {\n\t\tif (this._pool) {\n\t\t\tconst poolConfig = this.createPoolConfig();\n\t\t\tconst poolId = `${poolConfig.host}|${poolConfig.port}|${poolConfig.user}`;\n\n\t\t\tlet sharedPools = SharedStore.get<{ [id: string]: { pool: Pool; useCounter: number } }>(\n\t\t\t\t\"mySqlPools\"\n\t\t\t);\n\t\t\tsharedPools ??= {};\n\t\t\tif (sharedPools[poolId]) {\n\t\t\t\t// Decrease the use counter and close the pool if no longer used\n\t\t\t\tsharedPools[poolId].useCounter--;\n\t\t\t\tif (sharedPools[poolId].useCounter <= 0) {\n\t\t\t\t\tawait this._pool.end();\n\t\t\t\t\tdelete sharedPools[poolId];\n\t\t\t\t}\n\t\t\t\tSharedStore.set(\"mySqlPools\", sharedPools);\n\t\t\t}\n\n\t\t\tthis._pool = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Wait for a database to exist.\n\t * @returns Nothing.\n\t * @internal\n\t */\n\tprivate async waitForDatabaseExists(): Promise<void> {\n\t\tfor (let attempt = 0; attempt < 20; attempt++) {\n\t\t\tconst databaseExists = await this.databaseExists();\n\t\t\tif (databaseExists) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait new Promise(resolve => setTimeout(resolve, 250));\n\t\t}\n\t}\n\n\t/**\n\t * Check if the table exists.\n\t * @returns True if the table exists, false otherwise.\n\t * @internal\n\t */\n\tprivate async tableExists(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst pool = this.getPool();\n\t\t\tconst [rows] = await pool.query(\"SHOW TABLES FROM ?? LIKE ?\", [\n\t\t\t\tthis._config.database,\n\t\t\t\tthis._config.tableName\n\t\t\t]);\n\t\t\treturn Is.arrayValue(rows);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Wait for a table to exist.\n\t * @returns Nothing.\n\t * @internal\n\t */\n\tprivate async waitForTableExists(): Promise<void> {\n\t\tfor (let attempt = 0; attempt < 20; attempt++) {\n\t\t\tconst tableExists = await this.tableExists();\n\t\t\tif (tableExists) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait new Promise(resolve => setTimeout(resolve, 250));\n\t\t}\n\t}\n\n\t/**\n\t * Wait for a table to not exist.\n\t * @returns Nothing.\n\t * @internal\n\t */\n\tprivate async waitForTableNotExists(): Promise<void> {\n\t\tfor (let attempt = 0; attempt < 20; attempt++) {\n\t\t\tconst tableExists = await this.tableExists();\n\t\t\tif (!tableExists) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait new Promise(resolve => setTimeout(resolve, 250));\n\t\t}\n\t}\n\n\t/**\n\t * Get or create the connection pool.\n\t * @returns The MySql connection pool.\n\t * @internal\n\t */\n\tprivate getPool(): Pool {\n\t\tif (!this._pool) {\n\t\t\tconst poolConfig = this.createPoolConfig();\n\t\t\tconst poolId = `${poolConfig.host}|${poolConfig.port}|${poolConfig.user}`;\n\n\t\t\tlet sharedPools = SharedStore.get<{ [id: string]: { pool: Pool; useCounter: number } }>(\n\t\t\t\t\"mySqlPools\"\n\t\t\t);\n\t\t\tsharedPools ??= {};\n\n\t\t\t// If there is no pool for the id, create it\n\t\t\tif (!sharedPools[poolId]) {\n\t\t\t\tsharedPools[poolId] = {\n\t\t\t\t\tpool: createPool(poolConfig),\n\t\t\t\t\tuseCounter: 0\n\t\t\t\t};\n\t\t\t\tSharedStore.set(\"mySqlPools\", sharedPools);\n\t\t\t}\n\t\t\t// Increase the use counter and return the pool\n\t\t\tsharedPools[poolId].useCounter++;\n\t\t\tthis._pool = sharedPools[poolId].pool;\n\t\t}\n\t\treturn this._pool;\n\t}\n\n\t/**\n\t * Create the connection pool configuration.\n\t * @returns The MySql pool configuration.\n\t * @internal\n\t */\n\tprivate createPoolConfig(): PoolOptions {\n\t\tconst poolConfig = this._config.pool ?? {};\n\n\t\treturn {\n\t\t\thost: this._config.host,\n\t\t\tport: this._config.port ?? 3306,\n\t\t\tuser: this._config.user,\n\t\t\tpassword: this._config.password,\n\n\t\t\tconnectionLimit: poolConfig.connectionLimit ?? 10,\n\t\t\tmaxIdle: poolConfig.maxIdle ?? 10,\n\t\t\tidleTimeout: poolConfig.idleTimeout ?? 60000,\n\t\t\tenableKeepAlive: poolConfig.enableKeepAlive ?? true,\n\t\t\tkeepAliveInitialDelay: 0,\n\t\t\twaitForConnections: poolConfig.waitForConnections ?? true,\n\t\t\tqueueLimit: poolConfig.queueLimit ?? 0\n\t\t};\n\t}\n\n\t/**\n\t * Create an SQL condition clause.\n\t * @param objectPath The path for the nested object.\n\t * @param condition The conditions to create the query from.\n\t * @param whereClauses The where clauses to use in the query.\n\t * @param values The values to use in the query.\n\t * @internal\n\t */\n\tprivate buildQueryParameters(\n\t\tobjectPath: string,\n\t\tcondition: EntityCondition<T> | undefined,\n\t\twhereClauses: string[],\n\t\tvalues: unknown[]\n\t): void {\n\t\tif (Is.undefined(condition)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (\"conditions\" in condition) {\n\t\t\tif (condition.conditions.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst joinConditions: string[] = condition.conditions.map(c => {\n\t\t\t\tconst subWhereClauses: string[] = [];\n\t\t\t\tconst subValues: unknown[] = [];\n\t\t\t\tthis.buildQueryParameters(objectPath, c, subWhereClauses, subValues);\n\t\t\t\tvalues.push(...subValues);\n\t\t\t\treturn subWhereClauses.join(\" AND \");\n\t\t\t});\n\n\t\t\tconst logicalOperator = this.mapConditionalOperator(condition.logicalOperator);\n\t\t\tconst queryClause = joinConditions.filter(j => j.length > 0).join(` ${logicalOperator} `);\n\n\t\t\tif (queryClause.length > 0) {\n\t\t\t\twhereClauses.push(`(${queryClause})`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst schemaProp = this._entitySchema.properties?.find(p => p.property === condition.property);\n\t\tconst comparison = this.mapComparisonOperator(objectPath, condition, schemaProp?.type, values);\n\t\twhereClauses.push(comparison);\n\t}\n\n\t/**\n\t * Map the framework comparison operators to those in MySQL.\n\t * @param objectPath The prefix to use for the condition.\n\t * @param comparator The operator to map.\n\t * @param type The type of the property.\n\t * @param values The values to use in the query.\n\t * @returns The comparison expression.\n\t * @throws GeneralError if the comparison operator is not supported.\n\t * @internal\n\t */\n\tprivate mapComparisonOperator(\n\t\tobjectPath: string,\n\t\tcomparator: IComparator,\n\t\ttype: EntitySchemaPropertyType | undefined,\n\t\tvalues: unknown[]\n\t): string {\n\t\tlet prop = objectPath;\n\t\tif (prop.length > 0) {\n\t\t\tprop += \".\";\n\t\t}\n\n\t\tprop += comparator.property;\n\n\t\tif (comparator.comparison === ComparisonOperator.In) {\n\t\t\tconst inValues = Is.array(comparator.value) ? comparator.value : [comparator.value];\n\t\t\tvalues.push(...inValues.map(val => this.propertyToDbValue(val, type)));\n\t\t\tconst placeholders = inValues.map(() => \"?\").join(\", \");\n\t\t\treturn `\\`${prop}\\` IN (${placeholders})`;\n\t\t}\n\t\tconst dbValue = this.propertyToDbValue(comparator.value, type);\n\t\tvalues.push(dbValue);\n\n\t\tif (comparator.property.split(\".\").length > 1) {\n\t\t\tconst rootProp = comparator.property.split(\".\")[0];\n\t\t\tconst nestedPath = comparator.property.split(\".\").slice(1).join(\".\");\n\t\t\tconst rootSchema = this._entitySchema.properties?.find(p => p.property === rootProp);\n\t\t\tconst isArray = rootSchema?.type === EntitySchemaPropertyType.Array;\n\t\t\tconst jsonPath = isArray ? `$[*].${nestedPath}` : `$.${nestedPath}`;\n\t\t\tconst jsonExpr = `JSON_UNQUOTE(JSON_EXTRACT(\\`${rootProp}\\`, '${jsonPath}'))`;\n\n\t\t\tswitch (comparator.comparison) {\n\t\t\t\tcase ComparisonOperator.Includes: {\n\t\t\t\t\tvalues.pop();\n\t\t\t\t\tvalues.push(`%${String(comparator.value).toLowerCase()}%`);\n\t\t\t\t\treturn `LOWER(${jsonExpr}) LIKE ?`;\n\t\t\t\t}\n\t\t\t\tcase ComparisonOperator.NotEquals:\n\t\t\t\t\treturn `${jsonExpr} <> ?`;\n\t\t\t\tcase ComparisonOperator.GreaterThan:\n\t\t\t\t\treturn `${jsonExpr} > ?`;\n\t\t\t\tcase ComparisonOperator.LessThan:\n\t\t\t\t\treturn `${jsonExpr} < ?`;\n\t\t\t\tcase ComparisonOperator.GreaterThanOrEqual:\n\t\t\t\t\treturn `${jsonExpr} >= ?`;\n\t\t\t\tcase ComparisonOperator.LessThanOrEqual:\n\t\t\t\t\treturn `${jsonExpr} <= ?`;\n\t\t\t\tdefault:\n\t\t\t\t\treturn `${jsonExpr} = ?`;\n\t\t\t}\n\t\t}\n\n\t\tswitch (comparator.comparison) {\n\t\t\tcase ComparisonOperator.Equals:\n\t\t\t\tif (Is.object(comparator.value) || Is.array(comparator.value)) {\n\t\t\t\t\treturn `JSON_CONTAINS(\\`${prop}\\`, ?)`;\n\t\t\t\t}\n\t\t\t\treturn `\\`${prop}\\` = ?`;\n\t\t\tcase ComparisonOperator.NotEquals:\n\t\t\t\tif (Is.object(comparator.value) || Is.array(comparator.value)) {\n\t\t\t\t\treturn `NOT JSON_CONTAINS(\\`${prop}\\`, ?)`;\n\t\t\t\t}\n\t\t\t\treturn `\\`${prop}\\` <> ?`;\n\t\t\tcase ComparisonOperator.GreaterThan:\n\t\t\t\treturn `\\`${prop}\\` > ?`;\n\t\t\tcase ComparisonOperator.LessThan:\n\t\t\t\treturn `\\`${prop}\\` < ?`;\n\t\t\tcase ComparisonOperator.GreaterThanOrEqual:\n\t\t\t\treturn `\\`${prop}\\` >= ?`;\n\t\t\tcase ComparisonOperator.LessThanOrEqual:\n\t\t\t\treturn `\\`${prop}\\` <= ?`;\n\t\t\tcase ComparisonOperator.Includes: {\n\t\t\t\tif (type === EntitySchemaPropertyType.String) {\n\t\t\t\t\tvalues.pop();\n\t\t\t\t\tvalues.push(`%${String(comparator.value).toLowerCase()}%`);\n\t\t\t\t\treturn `LOWER(\\`${prop}\\`) LIKE ?`;\n\t\t\t\t}\n\t\t\t\treturn `JSON_CONTAINS(\\`${prop}\\`, ?)`;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, \"comparisonNotSupported\", {\n\t\t\t\t\tcomparison: comparator.comparison\n\t\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Format a value to insert into DB.\n\t * @param value The value to format.\n\t * @param type The type for the property.\n\t * @returns The value after conversion.\n\t * @internal\n\t */\n\tprivate propertyToDbValue(value: unknown, type?: EntitySchemaPropertyType): unknown {\n\t\tif (Is.object(value)) {\n\t\t\treturn JSON.stringify(value);\n\t\t}\n\n\t\tif (type === \"string\") {\n\t\t\treturn String(value);\n\t\t} else if (type === \"number\") {\n\t\t\treturn Number(value);\n\t\t} else if (type === \"boolean\") {\n\t\t\treturn Boolean(value);\n\t\t}\n\n\t\treturn value;\n\t}\n\n\t/**\n\t * Map the framework conditional operators to those in MySQL.\n\t * @param operator The operator to map.\n\t * @returns The conditional operator.\n\t * @throws GeneralError if the conditional operator is not supported.\n\t * @internal\n\t */\n\tprivate mapConditionalOperator(operator?: LogicalOperator): string {\n\t\tif ((operator ?? LogicalOperator.And) === LogicalOperator.And) {\n\t\t\treturn \"AND\";\n\t\t} else if (operator === LogicalOperator.Or) {\n\t\t\treturn \"OR\";\n\t\t}\n\n\t\tthrow new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, \"conditionalNotSupported\", {\n\t\t\toperator\n\t\t});\n\t}\n\n\t/**\n\t * Verify the conditions for the entity.\n\t * @param conditions The conditions to verify.\n\t * @internal\n\t */\n\tprivate verifyConditions(\n\t\tconditions: { property: keyof T; value: unknown }[],\n\t\tobj: { [key in keyof T]: unknown }\n\t): boolean {\n\t\treturn conditions.every(\n\t\t\tcondition => ObjectHelper.propertyGet(obj, condition.property as string) === condition.value\n\t\t);\n\t}\n\n\t/**\n\t * Map entity schema properties to SQL properties.\n\t * @returns The SQL properties as a string.\n\t * @throws GeneralError if the entity properties do not exist.\n\t */\n\tprivate mapMySqlProperties(): string {\n\t\tconst sqlTypeMap: { [key in EntitySchemaPropertyType]: string } = {\n\t\t\t[EntitySchemaPropertyType.String]: \"LONGTEXT\",\n\t\t\t[EntitySchemaPropertyType.Number]: \"FLOAT\",\n\t\t\t[EntitySchemaPropertyType.Integer]: \"INT\",\n\t\t\t[EntitySchemaPropertyType.Object]: \"JSON\",\n\t\t\t[EntitySchemaPropertyType.Array]: \"JSON\",\n\t\t\t[EntitySchemaPropertyType.Boolean]: \"TINYINT(1)\"\n\t\t};\n\n\t\tif (!this._entitySchema.properties) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMySqlEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"entitySchemaPropertiesUndefined\"\n\t\t\t);\n\t\t}\n\n\t\tconst primaryKeys: string[] = [];\n\n\t\tconst props: IEntitySchemaProperty<T>[] = [...this._entitySchema.properties];\n\n\t\tprops.unshift({\n\t\t\tproperty: MySqlEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\ttype: EntitySchemaPropertyType.String,\n\t\t\tisPrimary: true\n\t\t});\n\n\t\tconst columnDefinitions = props\n\t\t\t.map(prop => {\n\t\t\t\tlet sqlType = sqlTypeMap[prop.type] || \"TEXT\";\n\t\t\t\tif (prop.format) {\n\t\t\t\t\tswitch (prop.type) {\n\t\t\t\t\t\tcase \"string\":\n\t\t\t\t\t\t\tsqlType = \"LONGTEXT\";\n\t\t\t\t\t\t\tswitch (prop.format) {\n\t\t\t\t\t\t\t\tcase \"uuid\":\n\t\t\t\t\t\t\t\t\tsqlType = \"CHAR(36)\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"date\":\n\t\t\t\t\t\t\t\tcase \"date-time\":\n\t\t\t\t\t\t\t\t\tsqlType = \"LONGTEXT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\t\tsqlType = \"FLOAT\";\n\t\t\t\t\t\t\tswitch (prop.format) {\n\t\t\t\t\t\t\t\tcase \"float\":\n\t\t\t\t\t\t\t\t\tsqlType = \"FLOAT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"double\":\n\t\t\t\t\t\t\t\t\tsqlType = \"DOUBLE\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"integer\":\n\t\t\t\t\t\t\tsqlType = \"INT\";\n\t\t\t\t\t\t\tswitch (prop.format) {\n\t\t\t\t\t\t\t\tcase \"int8\":\n\t\t\t\t\t\t\t\tcase \"uint8\":\n\t\t\t\t\t\t\t\t\tsqlType = \"TINYINT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"int16\":\n\t\t\t\t\t\t\t\tcase \"uint16\":\n\t\t\t\t\t\t\t\t\tsqlType = \"SMALLINT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"int32\":\n\t\t\t\t\t\t\t\tcase \"uint32\":\n\t\t\t\t\t\t\t\t\tsqlType = \"INT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"int64\":\n\t\t\t\t\t\t\t\tcase \"uint64\":\n\t\t\t\t\t\t\t\t\tsqlType = \"BIGINT\";\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst columnName = String(prop.property);\n\t\t\t\tconst nullable = prop.optional ? \" NULL\" : \" NOT NULL\";\n\n\t\t\t\tif (prop.isPrimary) {\n\t\t\t\t\tif (sqlType === \"LONGTEXT\" || sqlType === \"TEXT\") {\n\t\t\t\t\t\tprimaryKeys.push(`\\`${columnName}\\`(255)`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tprimaryKeys.push(`\\`${columnName}\\``);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn `\\`${columnName}\\` ${sqlType}${nullable}`;\n\t\t\t})\n\t\t\t.join(\", \");\n\n\t\tconst primaryKeyDefinition =\n\t\t\tprimaryKeys.length > 0 ? `, PRIMARY KEY (${primaryKeys.join(\", \")})` : \"\";\n\t\treturn columnDefinitions + primaryKeyDefinition;\n\t}\n}\n"]}
package/docs/changelog.md CHANGED
@@ -1,4 +1,20 @@
1
- # @twin.org/entity-storage-connector-mysql - Changelog
1
+ # Changelog
2
+
3
+ ## [0.0.3-next.7](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.3-next.6...entity-storage-connector-mysql-v0.0.3-next.7) (2026-03-13)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * adding tests and fixes for dot notation ([#76](https://github.com/twinfoundation/entity-storage/issues/76)) ([3879337](https://github.com/twinfoundation/entity-storage/commit/387933797e33543e4d8b2d49b8beeb792512a4ff))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/entity-storage-models bumped from 0.0.3-next.6 to 0.0.3-next.7
16
+ * devDependencies
17
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.3-next.6 to 0.0.3-next.7
2
18
 
3
19
  ## [0.0.3-next.6](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.3-next.5...entity-storage-connector-mysql-v0.0.3-next.6) (2026-01-21)
4
20
 
package/docs/examples.md CHANGED
@@ -1 +1,105 @@
1
- # @twin.org/entity-storage-connector-mysql - Examples
1
+ # Entity Storage Connector MySQL Examples
2
+
3
+ This page focuses on full connector lifecycle work, from initial bootstrap and entity access to schema maintenance and connection shutdown.
4
+
5
+ ## MySqlEntityStorageConnector
6
+
7
+ ```typescript
8
+ import {
9
+ MySqlEntityStorageConnector,
10
+ type IMySqlEntityStorageConnectorConstructorOptions
11
+ } from '@twin.org/entity-storage-connector-mysql';
12
+ import {
13
+ ComparisonOperator,
14
+ LogicalOperator,
15
+ SortDirection,
16
+ type EntityCondition
17
+ } from '@twin.org/entity';
18
+
19
+ interface Profile {
20
+ id: string;
21
+ email: string;
22
+ status: 'active' | 'inactive';
23
+ createdAt: string;
24
+ }
25
+
26
+ const options: IMySqlEntityStorageConnectorConstructorOptions = {
27
+ entitySchema: 'Profile',
28
+ config: {
29
+ host: 'localhost',
30
+ port: 3306,
31
+ user: 'root',
32
+ password: 'root',
33
+ database: 'entity_storage',
34
+ tableName: 'profiles'
35
+ }
36
+ };
37
+
38
+ const connector = new MySqlEntityStorageConnector<Profile>(options);
39
+ await connector.bootstrap();
40
+
41
+ const className = connector.className();
42
+ const schema = connector.getSchema();
43
+
44
+ await connector.set({
45
+ id: 'profile-1',
46
+ email: 'ada@example.com',
47
+ status: 'active',
48
+ createdAt: '2026-03-09T10:30:00.000Z'
49
+ });
50
+
51
+ const byPrimaryKey = await connector.get('profile-1');
52
+ const bySecondaryIndex = await connector.get('ada@example.com', 'email');
53
+
54
+ const activeCondition: EntityCondition<Profile> = {
55
+ logicalOperator: LogicalOperator.And,
56
+ conditions: [
57
+ {
58
+ property: 'status',
59
+ comparison: ComparisonOperator.Equals,
60
+ value: 'active'
61
+ }
62
+ ]
63
+ };
64
+
65
+ const result = await connector.query(
66
+ activeCondition,
67
+ [{ property: 'createdAt', sortDirection: SortDirection.Descending }],
68
+ ['id', 'email', 'status'],
69
+ undefined,
70
+ 25
71
+ );
72
+
73
+ await connector.remove('profile-1');
74
+ ```
75
+
76
+ ```typescript
77
+ import { MySqlEntityStorageConnector } from '@twin.org/entity-storage-connector-mysql';
78
+
79
+ interface Profile {
80
+ id: string;
81
+ email: string;
82
+ status: 'active' | 'inactive';
83
+ createdAt: string;
84
+ }
85
+
86
+ const connector = new MySqlEntityStorageConnector<Profile>({
87
+ entitySchema: 'Profile',
88
+ config: {
89
+ host: 'localhost',
90
+ user: 'root',
91
+ password: 'root',
92
+ database: 'entity_storage',
93
+ tableName: 'profiles'
94
+ }
95
+ });
96
+
97
+ const databaseExists = await connector.databaseExists();
98
+ if (databaseExists) {
99
+ await connector.tableEmpty();
100
+ }
101
+
102
+ await connector.tableDrop();
103
+ await connector.stop();
104
+ await connector.close();
105
+ ```
@@ -34,7 +34,7 @@ The options for the connector.
34
34
 
35
35
  ## Properties
36
36
 
37
- ### CLASS\_NAME
37
+ ### CLASS\_NAME {#class_name}
38
38
 
39
39
  > `readonly` `static` **CLASS\_NAME**: `string`
40
40
 
@@ -42,7 +42,7 @@ Runtime name for the class.
42
42
 
43
43
  ## Methods
44
44
 
45
- ### className()
45
+ ### className() {#classname}
46
46
 
47
47
  > **className**(): `string`
48
48
 
@@ -60,7 +60,7 @@ The class name of the component.
60
60
 
61
61
  ***
62
62
 
63
- ### getSchema()
63
+ ### getSchema() {#getschema}
64
64
 
65
65
  > **getSchema**(): `IEntitySchema`
66
66
 
@@ -78,7 +78,7 @@ The schema for the entities.
78
78
 
79
79
  ***
80
80
 
81
- ### bootstrap()
81
+ ### bootstrap() {#bootstrap}
82
82
 
83
83
  > **bootstrap**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
84
84
 
@@ -104,7 +104,7 @@ A promise that resolves to a boolean indicating success.
104
104
 
105
105
  ***
106
106
 
107
- ### stop()
107
+ ### stop() {#stop}
108
108
 
109
109
  > **stop**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
110
110
 
@@ -130,7 +130,7 @@ Nothing.
130
130
 
131
131
  ***
132
132
 
133
- ### get()
133
+ ### get() {#get}
134
134
 
135
135
  > **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
136
136
 
@@ -168,7 +168,7 @@ The object if it can be found or undefined.
168
168
 
169
169
  ***
170
170
 
171
- ### set()
171
+ ### set() {#set}
172
172
 
173
173
  > **set**(`entity`, `conditions?`): `Promise`\<`void`\>
174
174
 
@@ -200,7 +200,7 @@ The id of the entity.
200
200
 
201
201
  ***
202
202
 
203
- ### remove()
203
+ ### remove() {#remove}
204
204
 
205
205
  > **remove**(`id`, `conditions?`): `Promise`\<`void`\>
206
206
 
@@ -232,7 +232,7 @@ Nothing.
232
232
 
233
233
  ***
234
234
 
235
- ### query()
235
+ ### query() {#query}
236
236
 
237
237
  > **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
238
238
 
@@ -283,7 +283,7 @@ and a cursor which can be used to request more entities.
283
283
 
284
284
  ***
285
285
 
286
- ### tableDrop()
286
+ ### tableDrop() {#tabledrop}
287
287
 
288
288
  > **tableDrop**(): `Promise`\<`void`\>
289
289
 
@@ -297,7 +297,7 @@ Nothing.
297
297
 
298
298
  ***
299
299
 
300
- ### tableEmpty()
300
+ ### tableEmpty() {#tableempty}
301
301
 
302
302
  > **tableEmpty**(): `Promise`\<`void`\>
303
303
 
@@ -311,7 +311,7 @@ Nothing.
311
311
 
312
312
  ***
313
313
 
314
- ### databaseExists()
314
+ ### databaseExists() {#databaseexists}
315
315
 
316
316
  > **databaseExists**(): `Promise`\<`boolean`\>
317
317
 
@@ -325,7 +325,7 @@ True if the database exists, false otherwise.
325
325
 
326
326
  ***
327
327
 
328
- ### close()
328
+ ### close() {#close}
329
329
 
330
330
  > **close**(): `Promise`\<`void`\>
331
331
 
@@ -4,7 +4,7 @@ Configuration for the MySql Entity Storage Connector.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### host
7
+ ### host {#host}
8
8
 
9
9
  > **host**: `string`
10
10
 
@@ -12,7 +12,7 @@ The host for the MySql instance.
12
12
 
13
13
  ***
14
14
 
15
- ### port?
15
+ ### port? {#port}
16
16
 
17
17
  > `optional` **port**: `number`
18
18
 
@@ -20,7 +20,7 @@ The port for the MySql instance.
20
20
 
21
21
  ***
22
22
 
23
- ### user
23
+ ### user {#user}
24
24
 
25
25
  > **user**: `string`
26
26
 
@@ -28,7 +28,7 @@ The user for the MySql instance.
28
28
 
29
29
  ***
30
30
 
31
- ### password
31
+ ### password {#password}
32
32
 
33
33
  > **password**: `string`
34
34
 
@@ -36,7 +36,7 @@ The password for the MySql instance.
36
36
 
37
37
  ***
38
38
 
39
- ### database
39
+ ### database {#database}
40
40
 
41
41
  > **database**: `string`
42
42
 
@@ -44,7 +44,7 @@ The name of the database to be used.
44
44
 
45
45
  ***
46
46
 
47
- ### tableName
47
+ ### tableName {#tablename}
48
48
 
49
49
  > **tableName**: `string`
50
50
 
@@ -52,7 +52,7 @@ The name of the table to be used.
52
52
 
53
53
  ***
54
54
 
55
- ### pool?
55
+ ### pool? {#pool}
56
56
 
57
57
  > `optional` **pool**: `object`
58
58
 
@@ -64,68 +64,32 @@ Optional connection pool configuration.
64
64
 
65
65
  Maximum number of connections in pool.
66
66
 
67
- ##### Default
68
-
69
- ```ts
70
- 10
71
- ```
72
-
73
67
  #### maxIdle?
74
68
 
75
69
  > `optional` **maxIdle**: `number`
76
70
 
77
71
  Maximum number of idle connections.
78
72
 
79
- ##### Default
80
-
81
- ```ts
82
- 10
83
- ```
84
-
85
73
  #### idleTimeout?
86
74
 
87
75
  > `optional` **idleTimeout**: `number`
88
76
 
89
77
  Time in ms before removing idle connection.
90
78
 
91
- ##### Default
92
-
93
- ```ts
94
- 60000 (1 minute)
95
- ```
96
-
97
79
  #### enableKeepAlive?
98
80
 
99
81
  > `optional` **enableKeepAlive**: `boolean`
100
82
 
101
83
  Enable TCP keep-alive.
102
84
 
103
- ##### Default
104
-
105
- ```ts
106
- true
107
- ```
108
-
109
85
  #### waitForConnections?
110
86
 
111
87
  > `optional` **waitForConnections**: `boolean`
112
88
 
113
89
  Wait for available connection when pool is full.
114
90
 
115
- ##### Default
116
-
117
- ```ts
118
- true
119
- ```
120
-
121
91
  #### queueLimit?
122
92
 
123
93
  > `optional` **queueLimit**: `number`
124
94
 
125
95
  Maximum queued requests (0 = unlimited).
126
-
127
- ##### Default
128
-
129
- ```ts
130
- 0
131
- ```
@@ -4,7 +4,7 @@ The options for the MySql entity storage connector constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### entitySchema
7
+ ### entitySchema {#entityschema}
8
8
 
9
9
  > **entitySchema**: `string`
10
10
 
@@ -12,7 +12,7 @@ The schema for the entity.
12
12
 
13
13
  ***
14
14
 
15
- ### partitionContextIds?
15
+ ### partitionContextIds? {#partitioncontextids}
16
16
 
17
17
  > `optional` **partitionContextIds**: `string`[]
18
18
 
@@ -20,21 +20,15 @@ The keys to use from the context ids to create partitions.
20
20
 
21
21
  ***
22
22
 
23
- ### loggingComponentType?
23
+ ### loggingComponentType? {#loggingcomponenttype}
24
24
 
25
25
  > `optional` **loggingComponentType**: `string`
26
26
 
27
27
  The type of logging component to use.
28
28
 
29
- #### Default
30
-
31
- ```ts
32
- logging
33
- ```
34
-
35
29
  ***
36
30
 
37
- ### config
31
+ ### config {#config}
38
32
 
39
33
  > **config**: [`IMySqlEntityStorageConnectorConfig`](IMySqlEntityStorageConnectorConfig.md)
40
34
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-connector-mysql",
3
- "version": "0.0.3-next.6",
4
- "description": "Entity Storage connector implementation using MySQL storage",
3
+ "version": "0.0.3-next.7",
4
+ "description": "MySQL connector for relational persistence with SQL querying.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/twinfoundation/entity-storage.git",
@@ -18,10 +18,10 @@
18
18
  "@twin.org/core": "next",
19
19
  "@twin.org/data-json-ld": "next",
20
20
  "@twin.org/entity": "next",
21
- "@twin.org/entity-storage-models": "0.0.3-next.6",
21
+ "@twin.org/entity-storage-models": "0.0.3-next.7",
22
22
  "@twin.org/logging-models": "next",
23
23
  "@twin.org/nameof": "next",
24
- "mysql2": "3.15.3"
24
+ "mysql2": "3.19.1"
25
25
  },
26
26
  "main": "./dist/es/index.js",
27
27
  "types": "./dist/types/index.d.ts",