@mikro-orm/sql 7.0.2-dev.9 → 7.0.2
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/AbstractSqlConnection.d.ts +95 -47
- package/AbstractSqlConnection.js +240 -232
- package/AbstractSqlDriver.d.ts +412 -155
- package/AbstractSqlDriver.js +2062 -1937
- package/AbstractSqlPlatform.d.ts +84 -73
- package/AbstractSqlPlatform.js +163 -158
- package/PivotCollectionPersister.d.ts +33 -15
- package/PivotCollectionPersister.js +158 -160
- package/README.md +128 -294
- package/SqlEntityManager.d.ts +68 -20
- package/SqlEntityManager.js +54 -37
- package/SqlEntityRepository.d.ts +15 -14
- package/SqlEntityRepository.js +24 -23
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -12
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +192 -194
- package/dialects/mysql/BaseMySqlPlatform.d.ts +64 -45
- package/dialects/mysql/BaseMySqlPlatform.js +134 -131
- package/dialects/mysql/MySqlExceptionConverter.d.ts +6 -6
- package/dialects/mysql/MySqlExceptionConverter.js +91 -77
- package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +3 -3
- package/dialects/mysql/MySqlNativeQueryBuilder.js +66 -69
- package/dialects/mysql/MySqlSchemaHelper.d.ts +39 -39
- package/dialects/mysql/MySqlSchemaHelper.js +327 -319
- package/dialects/oracledb/OracleDialect.d.ts +81 -52
- package/dialects/oracledb/OracleDialect.js +155 -149
- package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +12 -12
- package/dialects/oracledb/OracleNativeQueryBuilder.js +232 -236
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +108 -105
- package/dialects/postgresql/BasePostgreSqlPlatform.js +351 -350
- package/dialects/postgresql/FullTextType.d.ts +10 -6
- package/dialects/postgresql/FullTextType.js +51 -51
- package/dialects/postgresql/PostgreSqlExceptionConverter.d.ts +5 -5
- package/dialects/postgresql/PostgreSqlExceptionConverter.js +55 -43
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +4 -4
- package/dialects/postgresql/PostgreSqlSchemaHelper.d.ts +102 -82
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +711 -683
- package/dialects/sqlite/BaseSqliteConnection.d.ts +3 -5
- package/dialects/sqlite/BaseSqliteConnection.js +21 -19
- package/dialects/sqlite/NodeSqliteDialect.d.ts +1 -1
- package/dialects/sqlite/NodeSqliteDialect.js +23 -23
- package/dialects/sqlite/SqliteDriver.d.ts +1 -1
- package/dialects/sqlite/SqliteDriver.js +3 -3
- package/dialects/sqlite/SqliteExceptionConverter.d.ts +6 -6
- package/dialects/sqlite/SqliteExceptionConverter.js +67 -51
- package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +2 -2
- package/dialects/sqlite/SqliteNativeQueryBuilder.js +7 -7
- package/dialects/sqlite/SqlitePlatform.d.ts +63 -72
- package/dialects/sqlite/SqlitePlatform.js +139 -139
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +70 -60
- package/dialects/sqlite/SqliteSchemaHelper.js +533 -520
- package/package.json +4 -4
- package/plugin/index.d.ts +44 -35
- package/plugin/index.js +44 -36
- package/plugin/transformer.d.ts +117 -94
- package/plugin/transformer.js +890 -881
- package/query/ArrayCriteriaNode.d.ts +4 -4
- package/query/ArrayCriteriaNode.js +18 -18
- package/query/CriteriaNode.d.ts +35 -25
- package/query/CriteriaNode.js +133 -123
- package/query/CriteriaNodeFactory.d.ts +49 -6
- package/query/CriteriaNodeFactory.js +97 -94
- package/query/NativeQueryBuilder.d.ts +120 -117
- package/query/NativeQueryBuilder.js +484 -480
- package/query/ObjectCriteriaNode.d.ts +12 -12
- package/query/ObjectCriteriaNode.js +298 -282
- package/query/QueryBuilder.d.ts +1546 -904
- package/query/QueryBuilder.js +2270 -2145
- package/query/QueryBuilderHelper.d.ts +153 -72
- package/query/QueryBuilderHelper.js +1079 -1028
- package/query/ScalarCriteriaNode.d.ts +3 -3
- package/query/ScalarCriteriaNode.js +53 -46
- package/query/enums.d.ts +16 -14
- package/query/enums.js +16 -14
- package/query/raw.d.ts +16 -6
- package/query/raw.js +10 -10
- package/schema/DatabaseSchema.d.ts +73 -50
- package/schema/DatabaseSchema.js +331 -307
- package/schema/DatabaseTable.d.ts +96 -73
- package/schema/DatabaseTable.js +1012 -927
- package/schema/SchemaComparator.d.ts +58 -54
- package/schema/SchemaComparator.js +745 -719
- package/schema/SchemaHelper.d.ts +110 -80
- package/schema/SchemaHelper.js +676 -645
- package/schema/SqlSchemaGenerator.d.ts +79 -58
- package/schema/SqlSchemaGenerator.js +536 -501
- package/typings.d.ts +380 -266
|
@@ -2,76 +2,73 @@ import { LockMode, RawQueryFragment, Utils } from '@mikro-orm/core';
|
|
|
2
2
|
import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
|
|
3
3
|
/** @internal */
|
|
4
4
|
export class MySqlNativeQueryBuilder extends NativeQueryBuilder {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
this.parts.push('insert');
|
|
10
|
-
if (this.options.onConflict?.ignore) {
|
|
11
|
-
this.parts.push('ignore');
|
|
12
|
-
}
|
|
13
|
-
this.addHintComment();
|
|
14
|
-
this.parts.push(`into ${this.getTableName()}`);
|
|
15
|
-
if (Object.keys(this.options.data).length === 0) {
|
|
16
|
-
this.parts.push('default values');
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const parts = this.processInsertData();
|
|
20
|
-
this.parts.push(parts.join(', '));
|
|
5
|
+
compileInsert() {
|
|
6
|
+
if (!this.options.data) {
|
|
7
|
+
throw new Error('No data provided');
|
|
21
8
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
const map = {
|
|
27
|
-
[LockMode.PESSIMISTIC_READ]: 'lock in share mode',
|
|
28
|
-
[LockMode.PESSIMISTIC_WRITE]: 'for update',
|
|
29
|
-
[LockMode.PESSIMISTIC_PARTIAL_WRITE]: 'for update skip locked',
|
|
30
|
-
[LockMode.PESSIMISTIC_WRITE_OR_FAIL]: 'for update nowait',
|
|
31
|
-
[LockMode.PESSIMISTIC_PARTIAL_READ]: 'lock in share mode skip locked',
|
|
32
|
-
[LockMode.PESSIMISTIC_READ_OR_FAIL]: 'lock in share mode nowait',
|
|
33
|
-
};
|
|
34
|
-
if (this.options.lockMode !== LockMode.OPTIMISTIC) {
|
|
35
|
-
this.parts.push(map[this.options.lockMode]);
|
|
36
|
-
}
|
|
9
|
+
this.parts.push('insert');
|
|
10
|
+
if (this.options.onConflict?.ignore) {
|
|
11
|
+
this.parts.push('ignore');
|
|
37
12
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (clause.merge) {
|
|
44
|
-
this.parts.push('on duplicate key update');
|
|
45
|
-
if (Utils.isObject(clause.merge)) {
|
|
46
|
-
const fields = Object.keys(clause.merge).map(field => {
|
|
47
|
-
this.params.push(clause.merge[field]);
|
|
48
|
-
return `${this.quote(field)} = ?`;
|
|
49
|
-
});
|
|
50
|
-
this.parts.push(fields.join(', '));
|
|
51
|
-
}
|
|
52
|
-
else if (clause.merge.length === 0) {
|
|
53
|
-
const dataAsArray = Utils.asArray(this.options.data);
|
|
54
|
-
const keys = Object.keys(dataAsArray[0]);
|
|
55
|
-
this.parts.push(keys.map(key => `${this.quote(key)} = values(${this.quote(key)})`).join(', '));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const fields = clause.merge.map(key => `${this.quote(key)} = values(${this.quote(key)})`);
|
|
59
|
-
this.parts.push(fields.join(', '));
|
|
60
|
-
}
|
|
61
|
-
if (clause.where) {
|
|
62
|
-
this.parts.push(`where ${clause.where.sql}`);
|
|
63
|
-
this.params.push(...clause.where.params);
|
|
64
|
-
}
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
this.parts.push('on conflict');
|
|
68
|
-
if (clause.fields instanceof RawQueryFragment) {
|
|
69
|
-
this.parts.push(clause.fields.sql);
|
|
70
|
-
this.params.push(...clause.fields.params);
|
|
71
|
-
}
|
|
72
|
-
else if (clause.fields.length > 0) {
|
|
73
|
-
const fields = clause.fields.map(field => this.quote(field));
|
|
74
|
-
this.parts.push(`(${fields.join(', ')})`);
|
|
75
|
-
}
|
|
13
|
+
this.addHintComment();
|
|
14
|
+
this.parts.push(`into ${this.getTableName()}`);
|
|
15
|
+
if (Object.keys(this.options.data).length === 0) {
|
|
16
|
+
this.parts.push('default values');
|
|
17
|
+
return;
|
|
76
18
|
}
|
|
19
|
+
const parts = this.processInsertData();
|
|
20
|
+
this.parts.push(parts.join(', '));
|
|
21
|
+
}
|
|
22
|
+
addLockClause() {
|
|
23
|
+
if (!this.options.lockMode) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const map = {
|
|
27
|
+
[LockMode.PESSIMISTIC_READ]: 'lock in share mode',
|
|
28
|
+
[LockMode.PESSIMISTIC_WRITE]: 'for update',
|
|
29
|
+
[LockMode.PESSIMISTIC_PARTIAL_WRITE]: 'for update skip locked',
|
|
30
|
+
[LockMode.PESSIMISTIC_WRITE_OR_FAIL]: 'for update nowait',
|
|
31
|
+
[LockMode.PESSIMISTIC_PARTIAL_READ]: 'lock in share mode skip locked',
|
|
32
|
+
[LockMode.PESSIMISTIC_READ_OR_FAIL]: 'lock in share mode nowait',
|
|
33
|
+
};
|
|
34
|
+
if (this.options.lockMode !== LockMode.OPTIMISTIC) {
|
|
35
|
+
this.parts.push(map[this.options.lockMode]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
addOnConflictClause() {
|
|
39
|
+
const clause = this.options.onConflict;
|
|
40
|
+
if (!clause || clause.ignore) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (clause.merge) {
|
|
44
|
+
this.parts.push('on duplicate key update');
|
|
45
|
+
if (Utils.isObject(clause.merge)) {
|
|
46
|
+
const fields = Object.keys(clause.merge).map(field => {
|
|
47
|
+
this.params.push(clause.merge[field]);
|
|
48
|
+
return `${this.quote(field)} = ?`;
|
|
49
|
+
});
|
|
50
|
+
this.parts.push(fields.join(', '));
|
|
51
|
+
} else if (clause.merge.length === 0) {
|
|
52
|
+
const dataAsArray = Utils.asArray(this.options.data);
|
|
53
|
+
const keys = Object.keys(dataAsArray[0]);
|
|
54
|
+
this.parts.push(keys.map(key => `${this.quote(key)} = values(${this.quote(key)})`).join(', '));
|
|
55
|
+
} else {
|
|
56
|
+
const fields = clause.merge.map(key => `${this.quote(key)} = values(${this.quote(key)})`);
|
|
57
|
+
this.parts.push(fields.join(', '));
|
|
58
|
+
}
|
|
59
|
+
if (clause.where) {
|
|
60
|
+
this.parts.push(`where ${clause.where.sql}`);
|
|
61
|
+
this.params.push(...clause.where.params);
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.parts.push('on conflict');
|
|
66
|
+
if (clause.fields instanceof RawQueryFragment) {
|
|
67
|
+
this.parts.push(clause.fields.sql);
|
|
68
|
+
this.params.push(...clause.fields.params);
|
|
69
|
+
} else if (clause.fields.length > 0) {
|
|
70
|
+
const fields = clause.fields.map(field => this.quote(field));
|
|
71
|
+
this.parts.push(`(${fields.join(', ')})`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
77
74
|
}
|
|
@@ -5,43 +5,43 @@ import { SchemaHelper } from '../../schema/SchemaHelper.js';
|
|
|
5
5
|
import type { DatabaseSchema } from '../../schema/DatabaseSchema.js';
|
|
6
6
|
import type { DatabaseTable } from '../../schema/DatabaseTable.js';
|
|
7
7
|
export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
8
|
+
#private;
|
|
9
|
+
static readonly DEFAULT_VALUES: {
|
|
10
|
+
'now()': string[];
|
|
11
|
+
'current_timestamp(?)': string[];
|
|
12
|
+
'0': string[];
|
|
13
|
+
};
|
|
14
|
+
getSchemaBeginning(charset: string, disableForeignKeys?: boolean): string;
|
|
15
|
+
disableForeignKeysSQL(): string;
|
|
16
|
+
enableForeignKeysSQL(): string;
|
|
17
|
+
finalizeTable(table: DatabaseTable, charset: string, collate?: string): string;
|
|
18
|
+
getListTablesSQL(): string;
|
|
19
|
+
getListViewsSQL(): string;
|
|
20
|
+
loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection, schemaName?: string): Promise<void>;
|
|
21
|
+
loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[]): Promise<void>;
|
|
22
|
+
getAllIndexes(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<IndexDef[]>>;
|
|
23
|
+
getCreateIndexSQL(tableName: string, index: IndexDef, partialExpression?: boolean): string;
|
|
24
|
+
/**
|
|
25
|
+
* Build the column list for a MySQL index, with MySQL-specific handling for collation.
|
|
26
|
+
* MySQL requires collation to be specified as an expression: (column_name COLLATE collation_name)
|
|
27
|
+
*/
|
|
28
|
+
protected getIndexColumns(index: IndexDef): string;
|
|
29
|
+
/**
|
|
30
|
+
* Append MySQL-specific index suffixes like INVISIBLE.
|
|
31
|
+
*/
|
|
32
|
+
protected appendMySqlIndexSuffix(sql: string, index: IndexDef): string;
|
|
33
|
+
getAllColumns(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<Column[]>>;
|
|
34
|
+
getAllChecks(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<CheckDef[]>>;
|
|
35
|
+
getAllForeignKeys(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<Dictionary<ForeignKey>>>;
|
|
36
|
+
getPreAlterTable(tableDiff: TableDifference, safe: boolean): string[];
|
|
37
|
+
getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column): string;
|
|
38
|
+
getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string[];
|
|
39
|
+
getChangeColumnCommentSQL(tableName: string, to: Column, schemaName?: string): string;
|
|
40
|
+
alterTableColumn(column: Column, table: DatabaseTable, changedProperties: Set<string>): string[];
|
|
41
|
+
private getColumnDeclarationSQL;
|
|
42
|
+
getAllEnumDefinitions(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<Dictionary<string[]>>>;
|
|
43
|
+
private supportsCheckConstraints;
|
|
44
|
+
protected getChecksSQL(tables: Table[]): string;
|
|
45
|
+
normalizeDefaultValue(defaultValue: string, length: number): string | number;
|
|
46
|
+
protected wrap(val: string | null | undefined, type: Type<unknown>): string | null | undefined;
|
|
47
47
|
}
|