@mikro-orm/sql 7.0.4 → 7.0.5-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.
- package/AbstractSqlConnection.d.ts +58 -94
- package/AbstractSqlConnection.js +238 -235
- package/AbstractSqlDriver.d.ts +155 -410
- package/AbstractSqlDriver.js +1941 -2064
- package/AbstractSqlPlatform.d.ts +73 -83
- package/AbstractSqlPlatform.js +158 -162
- package/PivotCollectionPersister.d.ts +15 -33
- package/PivotCollectionPersister.js +160 -158
- package/README.md +1 -1
- package/SqlEntityManager.d.ts +22 -67
- package/SqlEntityManager.js +38 -54
- package/SqlEntityRepository.d.ts +14 -14
- package/SqlEntityRepository.js +23 -23
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -12
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +194 -192
- package/dialects/mysql/BaseMySqlPlatform.d.ts +45 -64
- package/dialects/mysql/BaseMySqlPlatform.js +131 -134
- package/dialects/mysql/MySqlExceptionConverter.d.ts +6 -6
- package/dialects/mysql/MySqlExceptionConverter.js +77 -91
- package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +3 -3
- package/dialects/mysql/MySqlNativeQueryBuilder.js +69 -66
- package/dialects/mysql/MySqlSchemaHelper.d.ts +39 -39
- package/dialects/mysql/MySqlSchemaHelper.js +319 -327
- package/dialects/oracledb/OracleDialect.d.ts +52 -81
- package/dialects/oracledb/OracleDialect.js +149 -155
- package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +12 -12
- package/dialects/oracledb/OracleNativeQueryBuilder.js +236 -232
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +106 -109
- package/dialects/postgresql/BasePostgreSqlPlatform.js +353 -354
- package/dialects/postgresql/FullTextType.d.ts +6 -10
- package/dialects/postgresql/FullTextType.js +51 -51
- package/dialects/postgresql/PostgreSqlExceptionConverter.d.ts +5 -5
- package/dialects/postgresql/PostgreSqlExceptionConverter.js +43 -55
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +4 -4
- package/dialects/postgresql/PostgreSqlSchemaHelper.d.ts +82 -102
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +705 -733
- package/dialects/sqlite/BaseSqliteConnection.d.ts +5 -3
- package/dialects/sqlite/BaseSqliteConnection.js +19 -21
- 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 +51 -67
- package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +2 -2
- package/dialects/sqlite/SqliteNativeQueryBuilder.js +7 -7
- package/dialects/sqlite/SqlitePlatform.d.ts +72 -63
- package/dialects/sqlite/SqlitePlatform.js +139 -139
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +60 -70
- package/dialects/sqlite/SqliteSchemaHelper.js +520 -533
- package/package.json +2 -2
- package/plugin/index.d.ts +35 -42
- package/plugin/index.js +36 -43
- package/plugin/transformer.d.ts +94 -117
- package/plugin/transformer.js +881 -890
- package/query/ArrayCriteriaNode.d.ts +4 -4
- package/query/ArrayCriteriaNode.js +18 -18
- package/query/CriteriaNode.d.ts +25 -35
- package/query/CriteriaNode.js +123 -133
- package/query/CriteriaNodeFactory.d.ts +6 -49
- package/query/CriteriaNodeFactory.js +94 -97
- package/query/NativeQueryBuilder.d.ts +118 -118
- package/query/NativeQueryBuilder.js +480 -484
- package/query/ObjectCriteriaNode.d.ts +12 -12
- package/query/ObjectCriteriaNode.js +282 -298
- package/query/QueryBuilder.d.ts +905 -1557
- package/query/QueryBuilder.js +2192 -2322
- package/query/QueryBuilderHelper.d.ts +72 -153
- package/query/QueryBuilderHelper.js +1028 -1079
- package/query/ScalarCriteriaNode.d.ts +3 -3
- package/query/ScalarCriteriaNode.js +46 -53
- package/query/enums.d.ts +14 -14
- package/query/enums.js +14 -14
- package/query/raw.d.ts +6 -16
- package/query/raw.js +10 -10
- package/schema/DatabaseSchema.d.ts +50 -73
- package/schema/DatabaseSchema.js +307 -331
- package/schema/DatabaseTable.d.ts +73 -96
- package/schema/DatabaseTable.js +927 -1012
- package/schema/SchemaComparator.d.ts +66 -70
- package/schema/SchemaComparator.js +740 -766
- package/schema/SchemaHelper.d.ts +95 -109
- package/schema/SchemaHelper.js +659 -675
- package/schema/SqlSchemaGenerator.d.ts +58 -78
- package/schema/SqlSchemaGenerator.js +501 -535
- package/typings.d.ts +266 -380
|
@@ -3,143 +3,143 @@ import { SqliteNativeQueryBuilder } from './SqliteNativeQueryBuilder.js';
|
|
|
3
3
|
import { SqliteSchemaHelper } from './SqliteSchemaHelper.js';
|
|
4
4
|
import { SqliteExceptionConverter } from './SqliteExceptionConverter.js';
|
|
5
5
|
export class SqlitePlatform extends AbstractSqlPlatform {
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
6
|
+
schemaHelper = new SqliteSchemaHelper(this);
|
|
7
|
+
exceptionConverter = new SqliteExceptionConverter();
|
|
8
|
+
/** @internal */
|
|
9
|
+
createNativeQueryBuilder() {
|
|
10
|
+
return new SqliteNativeQueryBuilder(this);
|
|
11
|
+
}
|
|
12
|
+
usesDefaultKeyword() {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
usesReturningStatement() {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
usesEnumCheckConstraints() {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
getCurrentTimestampSQL(length) {
|
|
22
|
+
return `(strftime('%s', 'now') * 1000)`;
|
|
23
|
+
}
|
|
24
|
+
getDateTimeTypeDeclarationSQL(column) {
|
|
25
|
+
return 'datetime';
|
|
26
|
+
}
|
|
27
|
+
getBeginTransactionSQL(options) {
|
|
28
|
+
return ['begin'];
|
|
29
|
+
}
|
|
30
|
+
getEnumTypeDeclarationSQL(column) {
|
|
31
|
+
if (column.items?.every(item => typeof item === 'string')) {
|
|
32
|
+
return 'text';
|
|
33
|
+
}
|
|
34
|
+
/* v8 ignore next */
|
|
35
|
+
return this.getTinyIntTypeDeclarationSQL(column);
|
|
36
|
+
}
|
|
37
|
+
getTinyIntTypeDeclarationSQL(column) {
|
|
38
|
+
return this.getIntegerTypeDeclarationSQL(column);
|
|
39
|
+
}
|
|
40
|
+
getSmallIntTypeDeclarationSQL(column) {
|
|
41
|
+
return this.getIntegerTypeDeclarationSQL(column);
|
|
42
|
+
}
|
|
43
|
+
getIntegerTypeDeclarationSQL(column) {
|
|
44
|
+
return 'integer';
|
|
45
|
+
}
|
|
46
|
+
getFloatDeclarationSQL() {
|
|
47
|
+
return 'real';
|
|
48
|
+
}
|
|
49
|
+
getBooleanTypeDeclarationSQL() {
|
|
50
|
+
return 'integer';
|
|
51
|
+
}
|
|
52
|
+
getCharTypeDeclarationSQL(column) {
|
|
53
|
+
return 'text';
|
|
54
|
+
}
|
|
55
|
+
getVarcharTypeDeclarationSQL(column) {
|
|
56
|
+
return 'text';
|
|
57
|
+
}
|
|
58
|
+
normalizeColumnType(type, options) {
|
|
59
|
+
const simpleType = this.extractSimpleType(type);
|
|
60
|
+
if (['varchar', 'text'].includes(simpleType)) {
|
|
61
|
+
return this.getVarcharTypeDeclarationSQL(options);
|
|
62
|
+
}
|
|
63
|
+
return simpleType;
|
|
64
|
+
}
|
|
65
|
+
convertsJsonAutomatically() {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* This is used to narrow the value of Date properties as they will be stored as timestamps in sqlite.
|
|
70
|
+
* We use this method to convert Dates to timestamps when computing the changeset, so we have the right
|
|
71
|
+
* data type in the payload as well as in original entity data. Without that, we would end up with diffs
|
|
72
|
+
* including all Date properties, as we would be comparing Date object with timestamp.
|
|
73
|
+
*/
|
|
74
|
+
processDateProperty(value) {
|
|
75
|
+
if (value instanceof Date) {
|
|
76
|
+
return +value;
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
getIndexName(tableName, columns, type) {
|
|
81
|
+
if (type === 'primary') {
|
|
82
|
+
return this.getDefaultPrimaryName(tableName, columns);
|
|
83
|
+
}
|
|
84
|
+
return super.getIndexName(tableName, columns, type);
|
|
85
|
+
}
|
|
86
|
+
supportsDeferredUniqueConstraints() {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* SQLite supports schemas via ATTACH DATABASE. Returns true when there are
|
|
91
|
+
* attached databases configured.
|
|
92
|
+
*/
|
|
93
|
+
supportsSchemas() {
|
|
94
|
+
const attachDatabases = this.config.get('attachDatabases');
|
|
95
|
+
return !!attachDatabases?.length;
|
|
96
|
+
}
|
|
97
|
+
getDefaultSchemaName() {
|
|
98
|
+
// Return 'main' only when schema support is active (i.e., databases are attached)
|
|
99
|
+
return this.supportsSchemas() ? 'main' : undefined;
|
|
100
|
+
}
|
|
101
|
+
getFullTextWhereClause() {
|
|
102
|
+
return `:column: match :query`;
|
|
103
|
+
}
|
|
104
|
+
escape(value) {
|
|
105
|
+
if (value == null) {
|
|
106
|
+
return 'null';
|
|
107
|
+
}
|
|
108
|
+
if (typeof value === 'boolean') {
|
|
109
|
+
return value ? 'true' : 'false';
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
112
|
+
return '' + value;
|
|
113
|
+
}
|
|
114
|
+
if (value instanceof Date) {
|
|
115
|
+
return '' + +value;
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
return value.map(v => this.escape(v)).join(', ');
|
|
119
|
+
}
|
|
120
|
+
if (Buffer.isBuffer(value)) {
|
|
121
|
+
return `X'${value.toString('hex')}'`;
|
|
122
|
+
}
|
|
123
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
124
|
+
}
|
|
125
|
+
convertVersionValue(value, prop) {
|
|
126
|
+
if (prop.runtimeType === 'Date') {
|
|
127
|
+
const ts = +value;
|
|
128
|
+
const str = new Date(ts)
|
|
129
|
+
.toISOString()
|
|
130
|
+
.replace('T', ' ')
|
|
131
|
+
.replace(/\.\d{3}Z$/, '');
|
|
132
|
+
return { $in: [ts, str] };
|
|
133
|
+
}
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
getJsonArrayElementPropertySQL(alias, property, _type) {
|
|
137
|
+
return `json_extract(${this.quoteIdentifier(alias)}.value, '$.${this.quoteJsonKey(property)}')`;
|
|
138
|
+
}
|
|
139
|
+
quoteValue(value) {
|
|
140
|
+
if (value instanceof Date) {
|
|
141
|
+
return '' + +value;
|
|
142
|
+
}
|
|
143
|
+
return super.quoteValue(value);
|
|
144
|
+
}
|
|
145
145
|
}
|
|
@@ -5,74 +5,64 @@ import type { Column, IndexDef, Table, TableDifference } from '../../typings.js'
|
|
|
5
5
|
import type { DatabaseTable } from '../../schema/DatabaseTable.js';
|
|
6
6
|
import type { DatabaseSchema } from '../../schema/DatabaseSchema.js';
|
|
7
7
|
export declare class SqliteSchemaHelper 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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*/
|
|
69
|
-
isImplicitIndex(name: string): boolean;
|
|
70
|
-
dropIndex(table: string, index: IndexDef, oldIndexName?: string): string;
|
|
71
|
-
/**
|
|
72
|
-
* SQLite does not support schema-qualified table names in REFERENCES clauses.
|
|
73
|
-
* Foreign key references can only point to tables in the same database.
|
|
74
|
-
*/
|
|
75
|
-
getReferencedTableName(referencedTableName: string, schema?: string): string;
|
|
76
|
-
alterTable(diff: TableDifference, safe?: boolean): string[];
|
|
77
|
-
private getAlterTempTableSQL;
|
|
8
|
+
disableForeignKeysSQL(): string;
|
|
9
|
+
enableForeignKeysSQL(): string;
|
|
10
|
+
supportsSchemaConstraints(): boolean;
|
|
11
|
+
getCreateNamespaceSQL(name: string): string;
|
|
12
|
+
getDropNamespaceSQL(name: string): string;
|
|
13
|
+
getListTablesSQL(): string;
|
|
14
|
+
getAllTables(connection: AbstractSqlConnection, schemas?: string[]): Promise<Table[]>;
|
|
15
|
+
getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
|
|
16
|
+
private getIgnoredViewsCondition;
|
|
17
|
+
getListViewsSQL(): string;
|
|
18
|
+
loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection, schemaName?: string): Promise<void>;
|
|
19
|
+
getDropDatabaseSQL(name: string): string;
|
|
20
|
+
loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[]): Promise<void>;
|
|
21
|
+
createTable(table: DatabaseTable, alter?: boolean): string[];
|
|
22
|
+
createTableColumn(column: Column, table: DatabaseTable, _changedProperties?: Set<string>): string | undefined;
|
|
23
|
+
getAddColumnsSQL(table: DatabaseTable, columns: Column[], diff?: TableDifference): string[];
|
|
24
|
+
dropForeignKey(tableName: string, constraintName: string): string;
|
|
25
|
+
getDropColumnsSQL(tableName: string, columns: Column[], schemaName?: string): string;
|
|
26
|
+
getCreateIndexSQL(tableName: string, index: IndexDef): string;
|
|
27
|
+
private parseTableDefinition;
|
|
28
|
+
/**
|
|
29
|
+
* Returns schema prefix for pragma and sqlite_master queries.
|
|
30
|
+
* Returns empty string for main database (no prefix needed).
|
|
31
|
+
*/
|
|
32
|
+
private getSchemaPrefix;
|
|
33
|
+
/**
|
|
34
|
+
* Returns all database names excluding 'temp'.
|
|
35
|
+
*/
|
|
36
|
+
private getDatabaseList;
|
|
37
|
+
/**
|
|
38
|
+
* Extracts the SELECT part from a CREATE VIEW statement.
|
|
39
|
+
*/
|
|
40
|
+
private extractViewDefinition;
|
|
41
|
+
private getColumns;
|
|
42
|
+
/**
|
|
43
|
+
* SQLite strips outer parentheses from expression defaults (`DEFAULT (expr)` → `expr` in pragma).
|
|
44
|
+
* We need to add them back so they match what we generate in DDL.
|
|
45
|
+
*/
|
|
46
|
+
private wrapExpressionDefault;
|
|
47
|
+
private getEnumDefinitions;
|
|
48
|
+
getPrimaryKeys(connection: AbstractSqlConnection, indexes: IndexDef[], tableName: string, schemaName?: string): Promise<string[]>;
|
|
49
|
+
private getIndexes;
|
|
50
|
+
private getChecks;
|
|
51
|
+
private getColumnDefinitions;
|
|
52
|
+
private getForeignKeys;
|
|
53
|
+
getManagementDbName(): string;
|
|
54
|
+
getCreateDatabaseSQL(name: string): string;
|
|
55
|
+
databaseExists(connection: Connection, name: string): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Implicit indexes will be ignored when diffing
|
|
58
|
+
*/
|
|
59
|
+
isImplicitIndex(name: string): boolean;
|
|
60
|
+
dropIndex(table: string, index: IndexDef, oldIndexName?: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* SQLite does not support schema-qualified table names in REFERENCES clauses.
|
|
63
|
+
* Foreign key references can only point to tables in the same database.
|
|
64
|
+
*/
|
|
65
|
+
getReferencedTableName(referencedTableName: string, schema?: string): string;
|
|
66
|
+
alterTable(diff: TableDifference, safe?: boolean): string[];
|
|
67
|
+
private getAlterTempTableSQL;
|
|
78
68
|
}
|