@mikro-orm/sql 7.2.9-dev.12 → 7.2.9-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.
@@ -1130,6 +1130,7 @@ export class AbstractSqlDriver extends DatabaseDriver {
1130
1130
  }
1131
1131
  }
1132
1132
  }
1133
+ const scalarColumn = prop.fieldNames.length > 1 && !prop.polymorphic ? this.getScalarFieldName(prop) : undefined;
1133
1134
  prop.fieldNames.forEach((fieldName, fieldNameIdx) => {
1134
1135
  if (fields.has(fieldName) || (prop.ownColumns && !prop.ownColumns.includes(fieldName))) {
1135
1136
  return;
@@ -1151,7 +1152,15 @@ export class AbstractSqlDriver extends DatabaseDriver {
1151
1152
  sql += '?';
1152
1153
  }
1153
1154
  params.push(...pks);
1154
- addParams(prop, prop.fieldNames.length > 1 ? data[idx][key]?.[fieldNameIdx] : data[idx][key]);
1155
+ const value = data[idx][key];
1156
+ const scalar = Array.isArray(value) && value.length === 1 ? value[0] : value;
1157
+ // a composite FK given as a scalar holds only the target PK, written to the column that references it
1158
+ if (scalarColumn && !isRaw(scalar) && Utils.isPrimaryKey(scalar)) {
1159
+ addParams(prop, (fieldName === scalarColumn ? scalar : null));
1160
+ }
1161
+ else {
1162
+ addParams(prop, prop.fieldNames.length > 1 ? value?.[fieldNameIdx] : value);
1163
+ }
1155
1164
  }
1156
1165
  });
1157
1166
  sql += ` else ${this.platform.quoteIdentifier(fieldName)} end, `;
@@ -62,6 +62,7 @@ export declare class MySqlSchemaHelper extends SchemaHelper {
62
62
  protected getChecksSQL(tables: Table[]): string;
63
63
  normalizeDefaultValue(defaultValue: string, length: number): string | number;
64
64
  protected wrap(val: string | null | undefined, type: Type<unknown>): string | null | undefined;
65
+ normalizeExpression(expr: string): string;
65
66
  /** Decodes the backslash escapes of an introspected string literal. */
66
67
  unescapeDefault(val: string): string;
67
68
  }
@@ -295,12 +295,14 @@ export class MySqlSchemaHelper extends SchemaHelper {
295
295
  const ret = {};
296
296
  for (const check of allChecks) {
297
297
  const key = this.getTableKey(check);
298
+ // string literals come back escaped twice, decoded one level the same as the defaults in `wrap()`
299
+ const expression = check.expression.replace(/\\(.)/gs, '$1');
298
300
  ret[key] ??= [];
299
301
  ret[key].push({
300
302
  name: check.name,
301
303
  columnName: check.column_name,
302
- definition: `check ${check.expression}`,
303
- expression: check.expression.replace(/^\((.*)\)$/, '$1'),
304
+ definition: `check ${expression}`,
305
+ expression: expression.replace(/^\((.*)\)$/, '$1'),
304
306
  });
305
307
  }
306
308
  return ret;
@@ -610,6 +612,10 @@ export class MySqlSchemaHelper extends SchemaHelper {
610
612
  const stringType = type instanceof StringType || type instanceof TextType || type instanceof EnumType;
611
613
  return stringType ? this.platform.quoteDefaultValue(val) : val;
612
614
  }
615
+ normalizeExpression(expr) {
616
+ // `\'` and `''` are the same quote inside a literal
617
+ return expr.replace(/\\(.)/gs, (escape, char) => (char === "'" ? "''" : escape));
618
+ }
613
619
  /** Decodes the backslash escapes of an introspected string literal. */
614
620
  unescapeDefault(val) {
615
621
  const sqlEscapes = { 0: '\0', b: '\b', n: '\n', r: '\r', t: '\t', Z: '\x1a' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.2.9-dev.12",
3
+ "version": "7.2.9-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.8"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.2.9-dev.12"
56
+ "@mikro-orm/core": "7.2.9-dev.14"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"