@mikro-orm/sql 7.0.15 → 7.0.16-dev.1

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.
Files changed (89) hide show
  1. package/AbstractSqlConnection.d.ts +58 -94
  2. package/AbstractSqlConnection.js +238 -235
  3. package/AbstractSqlDriver.d.ts +155 -410
  4. package/AbstractSqlDriver.js +1972 -2100
  5. package/AbstractSqlPlatform.d.ts +76 -86
  6. package/AbstractSqlPlatform.js +167 -169
  7. package/PivotCollectionPersister.d.ts +15 -33
  8. package/PivotCollectionPersister.js +160 -158
  9. package/README.md +1 -1
  10. package/SqlEntityManager.d.ts +22 -67
  11. package/SqlEntityManager.js +38 -54
  12. package/SqlEntityRepository.d.ts +14 -14
  13. package/SqlEntityRepository.js +23 -23
  14. package/SqlMikroORM.d.ts +8 -49
  15. package/SqlMikroORM.js +8 -8
  16. package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -12
  17. package/dialects/mssql/MsSqlNativeQueryBuilder.js +201 -199
  18. package/dialects/mysql/BaseMySqlPlatform.d.ts +46 -65
  19. package/dialects/mysql/BaseMySqlPlatform.js +134 -137
  20. package/dialects/mysql/MySqlExceptionConverter.d.ts +6 -6
  21. package/dialects/mysql/MySqlExceptionConverter.js +77 -91
  22. package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +3 -3
  23. package/dialects/mysql/MySqlNativeQueryBuilder.js +69 -66
  24. package/dialects/mysql/MySqlSchemaHelper.d.ts +39 -58
  25. package/dialects/mysql/MySqlSchemaHelper.js +319 -327
  26. package/dialects/oracledb/OracleDialect.d.ts +52 -81
  27. package/dialects/oracledb/OracleDialect.js +149 -155
  28. package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +12 -12
  29. package/dialects/oracledb/OracleNativeQueryBuilder.js +243 -239
  30. package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +107 -110
  31. package/dialects/postgresql/BasePostgreSqlPlatform.js +369 -370
  32. package/dialects/postgresql/FullTextType.d.ts +6 -10
  33. package/dialects/postgresql/FullTextType.js +51 -51
  34. package/dialects/postgresql/PostgreSqlExceptionConverter.d.ts +5 -5
  35. package/dialects/postgresql/PostgreSqlExceptionConverter.js +43 -55
  36. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
  37. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +4 -4
  38. package/dialects/postgresql/PostgreSqlSchemaHelper.d.ts +82 -117
  39. package/dialects/postgresql/PostgreSqlSchemaHelper.js +712 -748
  40. package/dialects/sqlite/BaseSqliteConnection.d.ts +5 -3
  41. package/dialects/sqlite/BaseSqliteConnection.js +19 -21
  42. package/dialects/sqlite/NodeSqliteDialect.d.ts +1 -1
  43. package/dialects/sqlite/NodeSqliteDialect.js +23 -23
  44. package/dialects/sqlite/SqliteDriver.d.ts +1 -1
  45. package/dialects/sqlite/SqliteDriver.js +3 -3
  46. package/dialects/sqlite/SqliteExceptionConverter.d.ts +6 -6
  47. package/dialects/sqlite/SqliteExceptionConverter.js +51 -67
  48. package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +2 -2
  49. package/dialects/sqlite/SqliteNativeQueryBuilder.js +7 -7
  50. package/dialects/sqlite/SqlitePlatform.d.ts +73 -64
  51. package/dialects/sqlite/SqlitePlatform.js +143 -143
  52. package/dialects/sqlite/SqliteSchemaHelper.d.ts +61 -78
  53. package/dialects/sqlite/SqliteSchemaHelper.js +522 -541
  54. package/package.json +2 -2
  55. package/plugin/index.d.ts +35 -42
  56. package/plugin/index.js +36 -43
  57. package/plugin/transformer.d.ts +102 -136
  58. package/plugin/transformer.js +988 -1010
  59. package/query/ArrayCriteriaNode.d.ts +4 -4
  60. package/query/ArrayCriteriaNode.js +18 -18
  61. package/query/CriteriaNode.d.ts +25 -35
  62. package/query/CriteriaNode.js +132 -142
  63. package/query/CriteriaNodeFactory.d.ts +6 -49
  64. package/query/CriteriaNodeFactory.js +94 -97
  65. package/query/NativeQueryBuilder.d.ts +120 -120
  66. package/query/NativeQueryBuilder.js +501 -507
  67. package/query/ObjectCriteriaNode.d.ts +12 -12
  68. package/query/ObjectCriteriaNode.js +282 -298
  69. package/query/QueryBuilder.d.ts +906 -1558
  70. package/query/QueryBuilder.js +2217 -2346
  71. package/query/QueryBuilderHelper.d.ts +72 -153
  72. package/query/QueryBuilderHelper.js +1032 -1084
  73. package/query/ScalarCriteriaNode.d.ts +3 -3
  74. package/query/ScalarCriteriaNode.js +46 -53
  75. package/query/enums.d.ts +14 -14
  76. package/query/enums.js +14 -14
  77. package/query/raw.d.ts +6 -16
  78. package/query/raw.js +10 -10
  79. package/schema/DatabaseSchema.d.ts +50 -74
  80. package/schema/DatabaseSchema.js +331 -359
  81. package/schema/DatabaseTable.d.ts +73 -96
  82. package/schema/DatabaseTable.js +974 -1046
  83. package/schema/SchemaComparator.d.ts +66 -70
  84. package/schema/SchemaComparator.js +765 -790
  85. package/schema/SchemaHelper.d.ts +97 -128
  86. package/schema/SchemaHelper.js +668 -683
  87. package/schema/SqlSchemaGenerator.d.ts +59 -79
  88. package/schema/SqlSchemaGenerator.js +495 -525
  89. package/typings.d.ts +275 -405
@@ -1,93 +1,83 @@
1
- import {
2
- type RawQueryFragment,
3
- type Constructor,
4
- type EntityManager,
5
- type EntityRepository,
6
- type IDatabaseDriver,
7
- type IsolationLevel,
8
- type MikroORM,
9
- Platform,
10
- } from '@mikro-orm/core';
1
+ import { type RawQueryFragment, type Constructor, type EntityManager, type EntityRepository, type IDatabaseDriver, type IsolationLevel, type MikroORM, Platform } from '@mikro-orm/core';
11
2
  import { SqlSchemaGenerator } from './schema/SqlSchemaGenerator.js';
12
3
  import { type SchemaHelper } from './schema/SchemaHelper.js';
13
4
  import type { IndexDef } from './typings.js';
14
5
  import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
15
6
  /** Base class for SQL database platforms, providing SQL generation and quoting utilities. */
16
7
  export declare abstract class AbstractSqlPlatform extends Platform {
17
- #private;
18
- protected readonly schemaHelper?: SchemaHelper;
19
- usesPivotTable(): boolean;
20
- indexForeignKeys(): boolean;
21
- getRepositoryClass<T extends object>(): Constructor<EntityRepository<T>>;
22
- getSchemaHelper(): SchemaHelper | undefined;
23
- /** @inheritDoc */
24
- lookupExtensions(orm: MikroORM): void;
25
- getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): SqlSchemaGenerator;
26
- /** @internal */
27
- createNativeQueryBuilder(): NativeQueryBuilder;
28
- getBeginTransactionSQL(options?: { isolationLevel?: IsolationLevel; readOnly?: boolean }): string[];
29
- getCommitTransactionSQL(): string;
30
- getRollbackTransactionSQL(): string;
31
- getSavepointSQL(savepointName: string): string;
32
- getRollbackToSavepointSQL(savepointName: string): string;
33
- getReleaseSavepointSQL(savepointName: string): string;
34
- quoteValue(value: any): string;
35
- getSearchJsonPropertySQL(path: string, type: string, aliased: boolean): string | RawQueryFragment;
36
- getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean, value?: unknown): string | RawQueryFragment;
37
- /**
38
- * Quotes a key for use inside a JSON path expression (e.g. `$.key`).
39
- * Simple alphanumeric keys are left unquoted; others are wrapped in double quotes
40
- * with embedded `\` and `"` escaped per the JSON path string syntax.
41
- * @internal
42
- */
43
- quoteJsonKey(key: string): string;
44
- getJsonIndexDefinition(index: IndexDef): string[];
45
- supportsUnionWhere(): boolean;
46
- /** Whether the platform supports `count(distinct col1, col2)` with multiple columns. If false, a subquery wrapper is used instead. */
47
- supportsMultiColumnCountDistinct(): boolean;
48
- supportsSchemas(): boolean;
49
- /** @inheritDoc */
50
- generateCustomOrder(escapedColumn: string, values: unknown[]): string;
51
- /**
52
- * @internal
53
- */
54
- getOrderByExpression(column: string, direction: string, collation?: string): string[];
55
- /**
56
- * Quotes a collation name for use in COLLATE clauses.
57
- * @internal
58
- */
59
- quoteCollation(collation: string): string;
60
- /** @internal */
61
- protected validateCollationName(collation: string): void;
62
- /** @internal */
63
- validateJsonPropertyName(name: string): void;
64
- /**
65
- * Returns FROM clause for JSON array iteration.
66
- * @internal
67
- */
68
- getJsonArrayFromSQL(
69
- column: string,
70
- alias: string,
71
- _properties: {
72
- name: string;
73
- type: string;
74
- }[],
75
- ): string;
76
- /**
77
- * Returns SQL expression to access an element's property within a JSON array iteration.
78
- * @internal
79
- */
80
- getJsonArrayElementPropertySQL(alias: string, property: string, _type: string): string;
81
- /**
82
- * Wraps JSON array FROM clause and WHERE condition into a full EXISTS condition.
83
- * MySQL overrides this because `json_table` doesn't support correlated subqueries.
84
- * @internal
85
- */
86
- getJsonArrayExistsSQL(from: string, where: string): string;
87
- /**
88
- * Maps a runtime type name (e.g. 'string', 'number') to a driver-specific bind type constant.
89
- * Used by NativeQueryBuilder for output bindings.
90
- * @internal
91
- */
92
- mapToBindType(type: string): unknown;
8
+ #private;
9
+ protected readonly schemaHelper?: SchemaHelper;
10
+ usesPivotTable(): boolean;
11
+ indexForeignKeys(): boolean;
12
+ getRepositoryClass<T extends object>(): Constructor<EntityRepository<T>>;
13
+ getSchemaHelper(): SchemaHelper | undefined;
14
+ /** @inheritDoc */
15
+ lookupExtensions(orm: MikroORM): void;
16
+ getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): SqlSchemaGenerator;
17
+ /** @internal */
18
+ createNativeQueryBuilder(): NativeQueryBuilder;
19
+ getBeginTransactionSQL(options?: {
20
+ isolationLevel?: IsolationLevel;
21
+ readOnly?: boolean;
22
+ }): string[];
23
+ getCommitTransactionSQL(): string;
24
+ getRollbackTransactionSQL(): string;
25
+ getSavepointSQL(savepointName: string): string;
26
+ getRollbackToSavepointSQL(savepointName: string): string;
27
+ getReleaseSavepointSQL(savepointName: string): string;
28
+ quoteValue(value: any): string;
29
+ getSearchJsonPropertySQL(path: string, type: string, aliased: boolean): string | RawQueryFragment;
30
+ getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean, value?: unknown): string | RawQueryFragment;
31
+ /**
32
+ * Quotes a key for use inside a JSON path expression (e.g. `$.key`).
33
+ * Simple alphanumeric keys are left unquoted; others are wrapped in double quotes
34
+ * with embedded `\` and `"` escaped per the JSON path string syntax.
35
+ * @internal
36
+ */
37
+ quoteJsonKey(key: string): string;
38
+ getJsonIndexDefinition(index: IndexDef): string[];
39
+ supportsUnionWhere(): boolean;
40
+ /** Whether the platform supports `count(distinct col1, col2)` with multiple columns. If false, a subquery wrapper is used instead. */
41
+ supportsMultiColumnCountDistinct(): boolean;
42
+ supportsSchemas(): boolean;
43
+ /** @inheritDoc */
44
+ generateCustomOrder(escapedColumn: string, values: unknown[]): string;
45
+ /**
46
+ * @internal
47
+ */
48
+ getOrderByExpression(column: string, direction: string, collation?: string): string[];
49
+ /**
50
+ * Quotes a collation name for use in COLLATE clauses.
51
+ * @internal
52
+ */
53
+ quoteCollation(collation: string): string;
54
+ /** @internal */
55
+ protected validateCollationName(collation: string): void;
56
+ /** @internal */
57
+ validateJsonPropertyName(name: string): void;
58
+ /**
59
+ * Returns FROM clause for JSON array iteration.
60
+ * @internal
61
+ */
62
+ getJsonArrayFromSQL(column: string, alias: string, _properties: {
63
+ name: string;
64
+ type: string;
65
+ }[]): string;
66
+ /**
67
+ * Returns SQL expression to access an element's property within a JSON array iteration.
68
+ * @internal
69
+ */
70
+ getJsonArrayElementPropertySQL(alias: string, property: string, _type: string): string;
71
+ /**
72
+ * Wraps JSON array FROM clause and WHERE condition into a full EXISTS condition.
73
+ * MySQL overrides this because `json_table` doesn't support correlated subqueries.
74
+ * @internal
75
+ */
76
+ getJsonArrayExistsSQL(from: string, where: string): string;
77
+ /**
78
+ * Maps a runtime type name (e.g. 'string', 'number') to a driver-specific bind type constant.
79
+ * Used by NativeQueryBuilder for output bindings.
80
+ * @internal
81
+ */
82
+ mapToBindType(type: string): unknown;
93
83
  }
@@ -1,175 +1,173 @@
1
- import { isRaw, JsonProperty, Platform, raw, Utils } from '@mikro-orm/core';
1
+ import { isRaw, JsonProperty, Platform, raw, Utils, } from '@mikro-orm/core';
2
2
  import { SqlEntityRepository } from './SqlEntityRepository.js';
3
3
  import { SqlSchemaGenerator } from './schema/SqlSchemaGenerator.js';
4
4
  import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
5
5
  /** Base class for SQL database platforms, providing SQL generation and quoting utilities. */
6
6
  export class AbstractSqlPlatform extends Platform {
7
- static #JSON_PROPERTY_NAME_RE = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
8
- schemaHelper;
9
- usesPivotTable() {
10
- return true;
11
- }
12
- indexForeignKeys() {
13
- return true;
14
- }
15
- getRepositoryClass() {
16
- return SqlEntityRepository;
17
- }
18
- getSchemaHelper() {
19
- return this.schemaHelper;
20
- }
21
- /** @inheritDoc */
22
- lookupExtensions(orm) {
23
- SqlSchemaGenerator.register(orm);
24
- }
25
- /* v8 ignore next: kept for type inference only */
26
- getSchemaGenerator(driver, em) {
27
- return new SqlSchemaGenerator(em ?? driver);
28
- }
29
- /** @internal */
30
- /* v8 ignore next */
31
- createNativeQueryBuilder() {
32
- return new NativeQueryBuilder(this);
33
- }
34
- getBeginTransactionSQL(options) {
35
- if (options?.isolationLevel) {
36
- return [`set transaction isolation level ${options.isolationLevel}`, 'begin'];
37
- }
38
- return ['begin'];
39
- }
40
- getCommitTransactionSQL() {
41
- return 'commit';
42
- }
43
- getRollbackTransactionSQL() {
44
- return 'rollback';
45
- }
46
- getSavepointSQL(savepointName) {
47
- return `savepoint ${this.quoteIdentifier(savepointName)}`;
48
- }
49
- getRollbackToSavepointSQL(savepointName) {
50
- return `rollback to savepoint ${this.quoteIdentifier(savepointName)}`;
51
- }
52
- getReleaseSavepointSQL(savepointName) {
53
- return `release savepoint ${this.quoteIdentifier(savepointName)}`;
54
- }
55
- quoteValue(value) {
56
- if (isRaw(value)) {
57
- return this.formatQuery(value.sql, value.params);
58
- }
59
- if (Utils.isPlainObject(value) || value?.[JsonProperty]) {
60
- return this.escape(JSON.stringify(value));
61
- }
62
- return this.escape(value);
63
- }
64
- getSearchJsonPropertySQL(path, type, aliased) {
65
- return this.getSearchJsonPropertyKey(path.split('->'), type, aliased);
66
- }
67
- getSearchJsonPropertyKey(path, type, aliased, value) {
68
- const [a, ...b] = path;
69
- const jsonPath = this.quoteValue(`$.${b.map(this.quoteJsonKey).join('.')}`);
70
- if (aliased) {
71
- return raw(alias => `json_extract(${this.quoteIdentifier(`${alias}.${a}`)}, ${jsonPath})`);
72
- }
73
- return raw(`json_extract(${this.quoteIdentifier(a)}, ${jsonPath})`);
74
- }
75
- /**
76
- * Quotes a key for use inside a JSON path expression (e.g. `$.key`).
77
- * Simple alphanumeric keys are left unquoted; others are wrapped in double quotes
78
- * with embedded `\` and `"` escaped per the JSON path string syntax.
79
- * @internal
80
- */
81
- quoteJsonKey(key) {
82
- if (/^[a-z]\w*$/i.test(key)) {
83
- return key;
84
- }
85
- return `"${key.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`;
86
- }
87
- getJsonIndexDefinition(index) {
88
- return index.columnNames.map(column => {
89
- if (!column.includes('.')) {
90
- return column;
91
- }
92
- const [root, ...path] = column.split('.');
93
- return `(json_extract(${root}, '$.${path.join('.')}'))`;
94
- });
95
- }
96
- supportsUnionWhere() {
97
- return true;
98
- }
99
- /** Whether the platform supports `count(distinct col1, col2)` with multiple columns. If false, a subquery wrapper is used instead. */
100
- supportsMultiColumnCountDistinct() {
101
- return false;
102
- }
103
- supportsSchemas() {
104
- return false;
105
- }
106
- /** @inheritDoc */
107
- generateCustomOrder(escapedColumn, values) {
108
- let ret = '(case ';
109
- values.forEach((v, i) => {
110
- ret += `when ${escapedColumn} = ${this.quoteValue(v)} then ${i} `;
111
- });
112
- return ret + 'else null end)';
113
- }
114
- /**
115
- * @internal
116
- */
117
- getOrderByExpression(column, direction, collation) {
118
- if (collation) {
119
- return [`${column} collate ${this.quoteCollation(collation)} ${direction.toLowerCase()}`];
120
- }
121
- return [`${column} ${direction.toLowerCase()}`];
122
- }
123
- /**
124
- * Quotes a collation name for use in COLLATE clauses.
125
- * @internal
126
- */
127
- quoteCollation(collation) {
128
- this.validateCollationName(collation);
129
- return this.quoteIdentifier(collation);
130
- }
131
- /** @internal */
132
- validateCollationName(collation) {
133
- if (!/^[\w]+$/.test(collation)) {
134
- throw new Error(`Invalid collation name: '${collation}'. Collation names must contain only word characters.`);
135
- }
136
- }
137
- /** @internal */
138
- validateJsonPropertyName(name) {
139
- if (!AbstractSqlPlatform.#JSON_PROPERTY_NAME_RE.test(name)) {
140
- throw new Error(
141
- `Invalid JSON property name: '${name}'. JSON property names must contain only alphanumeric characters and underscores.`,
142
- );
143
- }
144
- }
145
- /**
146
- * Returns FROM clause for JSON array iteration.
147
- * @internal
148
- */
149
- getJsonArrayFromSQL(column, alias, _properties) {
150
- return `json_each(${column}) as ${this.quoteIdentifier(alias)}`;
151
- }
152
- /**
153
- * Returns SQL expression to access an element's property within a JSON array iteration.
154
- * @internal
155
- */
156
- getJsonArrayElementPropertySQL(alias, property, _type) {
157
- return `${this.quoteIdentifier(alias)}.${this.quoteIdentifier(property)}`;
158
- }
159
- /**
160
- * Wraps JSON array FROM clause and WHERE condition into a full EXISTS condition.
161
- * MySQL overrides this because `json_table` doesn't support correlated subqueries.
162
- * @internal
163
- */
164
- getJsonArrayExistsSQL(from, where) {
165
- return `exists (select 1 from ${from} where ${where})`;
166
- }
167
- /**
168
- * Maps a runtime type name (e.g. 'string', 'number') to a driver-specific bind type constant.
169
- * Used by NativeQueryBuilder for output bindings.
170
- * @internal
171
- */
172
- mapToBindType(type) {
173
- return type;
174
- }
7
+ static #JSON_PROPERTY_NAME_RE = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
8
+ schemaHelper;
9
+ usesPivotTable() {
10
+ return true;
11
+ }
12
+ indexForeignKeys() {
13
+ return true;
14
+ }
15
+ getRepositoryClass() {
16
+ return SqlEntityRepository;
17
+ }
18
+ getSchemaHelper() {
19
+ return this.schemaHelper;
20
+ }
21
+ /** @inheritDoc */
22
+ lookupExtensions(orm) {
23
+ SqlSchemaGenerator.register(orm);
24
+ }
25
+ /* v8 ignore next: kept for type inference only */
26
+ getSchemaGenerator(driver, em) {
27
+ return new SqlSchemaGenerator(em ?? driver);
28
+ }
29
+ /** @internal */
30
+ /* v8 ignore next */
31
+ createNativeQueryBuilder() {
32
+ return new NativeQueryBuilder(this);
33
+ }
34
+ getBeginTransactionSQL(options) {
35
+ if (options?.isolationLevel) {
36
+ return [`set transaction isolation level ${options.isolationLevel}`, 'begin'];
37
+ }
38
+ return ['begin'];
39
+ }
40
+ getCommitTransactionSQL() {
41
+ return 'commit';
42
+ }
43
+ getRollbackTransactionSQL() {
44
+ return 'rollback';
45
+ }
46
+ getSavepointSQL(savepointName) {
47
+ return `savepoint ${this.quoteIdentifier(savepointName)}`;
48
+ }
49
+ getRollbackToSavepointSQL(savepointName) {
50
+ return `rollback to savepoint ${this.quoteIdentifier(savepointName)}`;
51
+ }
52
+ getReleaseSavepointSQL(savepointName) {
53
+ return `release savepoint ${this.quoteIdentifier(savepointName)}`;
54
+ }
55
+ quoteValue(value) {
56
+ if (isRaw(value)) {
57
+ return this.formatQuery(value.sql, value.params);
58
+ }
59
+ if (Utils.isPlainObject(value) || value?.[JsonProperty]) {
60
+ return this.escape(JSON.stringify(value));
61
+ }
62
+ return this.escape(value);
63
+ }
64
+ getSearchJsonPropertySQL(path, type, aliased) {
65
+ return this.getSearchJsonPropertyKey(path.split('->'), type, aliased);
66
+ }
67
+ getSearchJsonPropertyKey(path, type, aliased, value) {
68
+ const [a, ...b] = path;
69
+ const jsonPath = this.quoteValue(`$.${b.map(this.quoteJsonKey).join('.')}`);
70
+ if (aliased) {
71
+ return raw(alias => `json_extract(${this.quoteIdentifier(`${alias}.${a}`)}, ${jsonPath})`);
72
+ }
73
+ return raw(`json_extract(${this.quoteIdentifier(a)}, ${jsonPath})`);
74
+ }
75
+ /**
76
+ * Quotes a key for use inside a JSON path expression (e.g. `$.key`).
77
+ * Simple alphanumeric keys are left unquoted; others are wrapped in double quotes
78
+ * with embedded `\` and `"` escaped per the JSON path string syntax.
79
+ * @internal
80
+ */
81
+ quoteJsonKey(key) {
82
+ if (/^[a-z]\w*$/i.test(key)) {
83
+ return key;
84
+ }
85
+ return `"${key.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`;
86
+ }
87
+ getJsonIndexDefinition(index) {
88
+ return index.columnNames.map(column => {
89
+ if (!column.includes('.')) {
90
+ return column;
91
+ }
92
+ const [root, ...path] = column.split('.');
93
+ return `(json_extract(${root}, '$.${path.join('.')}'))`;
94
+ });
95
+ }
96
+ supportsUnionWhere() {
97
+ return true;
98
+ }
99
+ /** Whether the platform supports `count(distinct col1, col2)` with multiple columns. If false, a subquery wrapper is used instead. */
100
+ supportsMultiColumnCountDistinct() {
101
+ return false;
102
+ }
103
+ supportsSchemas() {
104
+ return false;
105
+ }
106
+ /** @inheritDoc */
107
+ generateCustomOrder(escapedColumn, values) {
108
+ let ret = '(case ';
109
+ values.forEach((v, i) => {
110
+ ret += `when ${escapedColumn} = ${this.quoteValue(v)} then ${i} `;
111
+ });
112
+ return ret + 'else null end)';
113
+ }
114
+ /**
115
+ * @internal
116
+ */
117
+ getOrderByExpression(column, direction, collation) {
118
+ if (collation) {
119
+ return [`${column} collate ${this.quoteCollation(collation)} ${direction.toLowerCase()}`];
120
+ }
121
+ return [`${column} ${direction.toLowerCase()}`];
122
+ }
123
+ /**
124
+ * Quotes a collation name for use in COLLATE clauses.
125
+ * @internal
126
+ */
127
+ quoteCollation(collation) {
128
+ this.validateCollationName(collation);
129
+ return this.quoteIdentifier(collation);
130
+ }
131
+ /** @internal */
132
+ validateCollationName(collation) {
133
+ if (!/^[\w]+$/.test(collation)) {
134
+ throw new Error(`Invalid collation name: '${collation}'. Collation names must contain only word characters.`);
135
+ }
136
+ }
137
+ /** @internal */
138
+ validateJsonPropertyName(name) {
139
+ if (!AbstractSqlPlatform.#JSON_PROPERTY_NAME_RE.test(name)) {
140
+ throw new Error(`Invalid JSON property name: '${name}'. JSON property names must contain only alphanumeric characters and underscores.`);
141
+ }
142
+ }
143
+ /**
144
+ * Returns FROM clause for JSON array iteration.
145
+ * @internal
146
+ */
147
+ getJsonArrayFromSQL(column, alias, _properties) {
148
+ return `json_each(${column}) as ${this.quoteIdentifier(alias)}`;
149
+ }
150
+ /**
151
+ * Returns SQL expression to access an element's property within a JSON array iteration.
152
+ * @internal
153
+ */
154
+ getJsonArrayElementPropertySQL(alias, property, _type) {
155
+ return `${this.quoteIdentifier(alias)}.${this.quoteIdentifier(property)}`;
156
+ }
157
+ /**
158
+ * Wraps JSON array FROM clause and WHERE condition into a full EXISTS condition.
159
+ * MySQL overrides this because `json_table` doesn't support correlated subqueries.
160
+ * @internal
161
+ */
162
+ getJsonArrayExistsSQL(from, where) {
163
+ return `exists (select 1 from ${from} where ${where})`;
164
+ }
165
+ /**
166
+ * Maps a runtime type name (e.g. 'string', 'number') to a driver-specific bind type constant.
167
+ * Used by NativeQueryBuilder for output bindings.
168
+ * @internal
169
+ */
170
+ mapToBindType(type) {
171
+ return type;
172
+ }
175
173
  }
@@ -1,36 +1,18 @@
1
- import {
2
- type Dictionary,
3
- type EntityMetadata,
4
- type EntityProperty,
5
- type Primary,
6
- type Transaction,
7
- } from '@mikro-orm/core';
1
+ import { type Dictionary, type EntityMetadata, type EntityProperty, type Primary, type Transaction } from '@mikro-orm/core';
8
2
  import { type AbstractSqlDriver } from './AbstractSqlDriver.js';
9
3
  export declare class PivotCollectionPersister<Entity extends object> {
10
- #private;
11
- constructor(
12
- meta: EntityMetadata<Entity>,
13
- driver: AbstractSqlDriver,
14
- ctx?: Transaction,
15
- schema?: string,
16
- loggerContext?: Dictionary,
17
- );
18
- enqueueUpdate(
19
- prop: EntityProperty<Entity>,
20
- insertDiff: Primary<Entity>[][],
21
- deleteDiff: Primary<Entity>[][] | boolean,
22
- pks: Primary<Entity>[],
23
- isInitialized?: boolean,
24
- ): void;
25
- private enqueueInsert;
26
- private enqueueUpsert;
27
- private createInsertStatement;
28
- private enqueueDelete;
29
- /**
30
- * Build the keys and data arrays for pivot table operations.
31
- * Handles polymorphic M:N by prepending the discriminator column/value.
32
- */
33
- private buildPivotKeysAndData;
34
- private collectStatements;
35
- execute(): Promise<void>;
4
+ #private;
5
+ constructor(meta: EntityMetadata<Entity>, driver: AbstractSqlDriver, ctx?: Transaction, schema?: string, loggerContext?: Dictionary);
6
+ enqueueUpdate(prop: EntityProperty<Entity>, insertDiff: Primary<Entity>[][], deleteDiff: Primary<Entity>[][] | boolean, pks: Primary<Entity>[], isInitialized?: boolean): void;
7
+ private enqueueInsert;
8
+ private enqueueUpsert;
9
+ private createInsertStatement;
10
+ private enqueueDelete;
11
+ /**
12
+ * Build the keys and data arrays for pivot table operations.
13
+ * Handles polymorphic M:N by prepending the discriminator column/value.
14
+ */
15
+ private buildPivotKeysAndData;
16
+ private collectStatements;
17
+ execute(): Promise<void>;
36
18
  }