@mikro-orm/sql 7.2.8-dev.13 → 7.2.8-dev.14

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.
@@ -18,6 +18,14 @@ export declare class BaseMySqlPlatform extends AbstractSqlPlatform {
18
18
  sortsNullsLowest(): boolean;
19
19
  /** mysql reads backslashes in string literals as escapes, so defaults need the same escaping as values (minus the needless `\"`). */
20
20
  quoteDefaultValue(value: string): string;
21
+ /** enum items are escaped the way mysql prints them back in `column_type`, so the next schema diff matches. */
22
+ getEnumTypeDeclarationSQL(column: {
23
+ items?: unknown[];
24
+ fieldNames: string[];
25
+ length?: number;
26
+ unsigned?: boolean;
27
+ autoincrement?: boolean;
28
+ }): string;
21
29
  supportsMultiColumnCountDistinct(): boolean;
22
30
  /** @internal */
23
31
  createNativeQueryBuilder(): MySqlNativeQueryBuilder;
@@ -12,6 +12,13 @@ export class BaseMySqlPlatform extends AbstractSqlPlatform {
12
12
  bigint: 'bigint',
13
13
  boolean: 'unsigned',
14
14
  };
15
+ #enumItemEscapes = {
16
+ '\0': '\\0',
17
+ '\n': '\\n',
18
+ '\r': '\\r',
19
+ "'": "''",
20
+ '\\': '\\\\',
21
+ };
15
22
  ORDER_BY_NULLS_TRANSLATE = {
16
23
  [QueryOrder.asc_nulls_first]: 'is not null',
17
24
  [QueryOrder.asc_nulls_last]: 'is null',
@@ -26,6 +33,11 @@ export class BaseMySqlPlatform extends AbstractSqlPlatform {
26
33
  quoteDefaultValue(value) {
27
34
  return this.quoteValue(value).replaceAll('\\"', '"');
28
35
  }
36
+ /** enum items are escaped the way mysql prints them back in `column_type`, so the next schema diff matches. */
37
+ getEnumTypeDeclarationSQL(column) {
38
+ const items = column.items?.map(item => typeof item === 'string' ? item.replace(/[\0\n\r'\\]/g, c => this.#enumItemEscapes[c]) : item);
39
+ return super.getEnumTypeDeclarationSQL({ ...column, items });
40
+ }
29
41
  supportsMultiColumnCountDistinct() {
30
42
  return true;
31
43
  }
@@ -572,10 +572,8 @@ export class MySqlSchemaHelper extends SchemaHelper {
572
572
  const enums = await connection.execute(sql, [], 'all', ctx);
573
573
  return enums.reduce((o, item) => {
574
574
  o[item.table_name] ??= {};
575
- o[item.table_name][item.column_name] = item.column_type
576
- .match(/enum\((.*)\)/)[1]
577
- .split(',')
578
- .map((item) => /'(.*)'/.exec(item)[1]);
575
+ // items can hold commas, doubled quotes and backslash escapes
576
+ o[item.table_name][item.column_name] = [...item.column_type.matchAll(/'((?:''|\\.|[^'\\])*)'/g)].map(([, value]) => this.unescapeDefault(value.replaceAll("''", "'")));
579
577
  return o;
580
578
  }, {});
581
579
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.2.8-dev.13",
3
+ "version": "7.2.8-dev.14",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.2.7"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.2.8-dev.13"
56
+ "@mikro-orm/core": "7.2.8-dev.14"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"