@mikro-orm/sql 7.2.6-dev.40 → 7.2.6-dev.41
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/AbstractSqlPlatform.js +1 -1
- package/dialects/mysql/BaseMySqlPlatform.d.ts +2 -0
- package/dialects/mysql/BaseMySqlPlatform.js +4 -0
- package/dialects/mysql/MySqlSchemaHelper.d.ts +1 -3
- package/dialects/mysql/MySqlSchemaHelper.js +2 -6
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +1 -1
- package/package.json +2 -2
- package/schema/DatabaseTable.js +2 -2
- package/schema/SchemaHelper.d.ts +2 -0
- package/schema/SchemaHelper.js +4 -0
package/AbstractSqlPlatform.js
CHANGED
|
@@ -96,7 +96,7 @@ export class AbstractSqlPlatform extends Platform {
|
|
|
96
96
|
return this.formatQuery(value.sql, value.params);
|
|
97
97
|
}
|
|
98
98
|
if (Utils.isPlainObject(value) || value?.[JsonProperty]) {
|
|
99
|
-
return this.escape(
|
|
99
|
+
return this.escape(this.convertJsonToDatabaseValue(value));
|
|
100
100
|
}
|
|
101
101
|
return this.escape(value);
|
|
102
102
|
}
|
|
@@ -16,6 +16,8 @@ export declare class BaseMySqlPlatform extends AbstractSqlPlatform {
|
|
|
16
16
|
};
|
|
17
17
|
/** mysql and mariadb treat null as the lowest value when no placement is requested. */
|
|
18
18
|
sortsNullsLowest(): boolean;
|
|
19
|
+
/** mysql reads backslashes in string literals as escapes, so defaults need the same escaping as values (minus the needless `\"`). */
|
|
20
|
+
quoteDefaultValue(value: string): string;
|
|
19
21
|
supportsMultiColumnCountDistinct(): boolean;
|
|
20
22
|
/** @internal */
|
|
21
23
|
createNativeQueryBuilder(): MySqlNativeQueryBuilder;
|
|
@@ -22,6 +22,10 @@ export class BaseMySqlPlatform extends AbstractSqlPlatform {
|
|
|
22
22
|
sortsNullsLowest() {
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
25
|
+
/** mysql reads backslashes in string literals as escapes, so defaults need the same escaping as values (minus the needless `\"`). */
|
|
26
|
+
quoteDefaultValue(value) {
|
|
27
|
+
return this.quoteValue(value).replaceAll('\\"', '"');
|
|
28
|
+
}
|
|
25
29
|
supportsMultiColumnCountDistinct() {
|
|
26
30
|
return true;
|
|
27
31
|
}
|
|
@@ -63,7 +63,5 @@ export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
|
63
63
|
normalizeDefaultValue(defaultValue: string, length: number): string | number;
|
|
64
64
|
protected wrap(val: string | null | undefined, type: Type<unknown>): string | null | undefined;
|
|
65
65
|
/** Decodes the backslash escapes of an introspected string literal. */
|
|
66
|
-
|
|
67
|
-
/** Metadata doubles embedded quotes and leaves `"` alone, so undo those two escapes of `quoteValue` while keeping the backslash form of control characters. */
|
|
68
|
-
protected quoteDefault(val: string): string;
|
|
66
|
+
unescapeDefault(val: string): string;
|
|
69
67
|
}
|
|
@@ -607,18 +607,14 @@ export class MySqlSchemaHelper extends SchemaHelper {
|
|
|
607
607
|
// text/blob literal defaults come back escaped twice with a charset introducer, e.g. `_utf8mb4\'it\\\'s\'` (JSON is parsed by the comparator)
|
|
608
608
|
const expression = type instanceof JsonType ? null : /^_\w+\\'(.*)\\'$/s.exec(val);
|
|
609
609
|
if (expression) {
|
|
610
|
-
return this.
|
|
610
|
+
return this.platform.quoteDefaultValue(this.unescapeDefault(expression[1].replace(/\\(.)/gs, '$1')));
|
|
611
611
|
}
|
|
612
612
|
const stringType = type instanceof StringType || type instanceof TextType || type instanceof EnumType;
|
|
613
|
-
return stringType ? this.
|
|
613
|
+
return stringType ? this.platform.quoteDefaultValue(val) : val;
|
|
614
614
|
}
|
|
615
615
|
/** Decodes the backslash escapes of an introspected string literal. */
|
|
616
616
|
unescapeDefault(val) {
|
|
617
617
|
const sqlEscapes = { 0: '\0', b: '\b', n: '\n', r: '\r', t: '\t', Z: '\x1a' };
|
|
618
618
|
return val.replace(/\\(.)/gs, (_, char) => sqlEscapes[char] ?? char);
|
|
619
619
|
}
|
|
620
|
-
/** Metadata doubles embedded quotes and leaves `"` alone, so undo those two escapes of `quoteValue` while keeping the backslash form of control characters. */
|
|
621
|
-
quoteDefault(val) {
|
|
622
|
-
return this.platform.quoteValue(val).replaceAll("\\'", "''").replaceAll('\\"', '"');
|
|
623
|
-
}
|
|
624
620
|
}
|
|
@@ -1226,7 +1226,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
1226
1226
|
if (!defaultValue || typeof defaultValue !== 'string') {
|
|
1227
1227
|
return super.normalizeDefaultValue(defaultValue, length, PostgreSqlSchemaHelper.DEFAULT_VALUES);
|
|
1228
1228
|
}
|
|
1229
|
-
const match = /^'(.*)'::(.*)
|
|
1229
|
+
const match = /^'(.*)'::(.*)$/s.exec(defaultValue);
|
|
1230
1230
|
if (match) {
|
|
1231
1231
|
if (match[2] === 'integer') {
|
|
1232
1232
|
return +match[1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.6-dev.
|
|
3
|
+
"version": "7.2.6-dev.41",
|
|
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.5"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.6-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.6-dev.41"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -876,9 +876,9 @@ export class DatabaseTable {
|
|
|
876
876
|
return +defaultValue;
|
|
877
877
|
}
|
|
878
878
|
// unquote string defaults if `raw = false`
|
|
879
|
-
const match = /^'(.*)'
|
|
879
|
+
const match = /^'(.*)'$/s.exec('' + val);
|
|
880
880
|
if (!raw && match) {
|
|
881
|
-
return match[1]
|
|
881
|
+
return schemaHelper.unescapeDefault(match[1]);
|
|
882
882
|
}
|
|
883
883
|
return '' + val;
|
|
884
884
|
}
|
package/schema/SchemaHelper.d.ts
CHANGED
|
@@ -163,6 +163,8 @@ export declare abstract class SchemaHelper {
|
|
|
163
163
|
getNamespaces(connection: AbstractSqlConnection, ctx?: Transaction): Promise<string[]>;
|
|
164
164
|
protected mapIndexes(indexes: IndexDef[]): Promise<IndexDef[]>;
|
|
165
165
|
mapForeignKeys(fks: any[], tableName: string, schemaName?: string): Dictionary;
|
|
166
|
+
/** Decodes the content of an introspected string literal, the inverse of `Platform.quoteDefaultValue()`. */
|
|
167
|
+
unescapeDefault(val: string): string;
|
|
166
168
|
normalizeDefaultValue(defaultValue: string | RawQueryFragment, length?: number, defaultValues?: Dictionary<string[]>): string | number;
|
|
167
169
|
getCreateDatabaseSQL(name: string): string;
|
|
168
170
|
getDropDatabaseSQL(name: string): string;
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -718,6 +718,10 @@ export class SchemaHelper {
|
|
|
718
718
|
return ret;
|
|
719
719
|
}, {});
|
|
720
720
|
}
|
|
721
|
+
/** Decodes the content of an introspected string literal, the inverse of `Platform.quoteDefaultValue()`. */
|
|
722
|
+
unescapeDefault(val) {
|
|
723
|
+
return val.replaceAll("''", "'");
|
|
724
|
+
}
|
|
721
725
|
normalizeDefaultValue(defaultValue, length, defaultValues = {}) {
|
|
722
726
|
if (defaultValue == null) {
|
|
723
727
|
return defaultValue;
|