@mikro-orm/sql 7.0.4 → 7.0.5-dev.0
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
|
@@ -1,366 +1,365 @@
|
|
|
1
|
-
import { ALIAS_REPLACEMENT, ARRAY_OPERATORS, raw, RawQueryFragment, Type, Utils } from '@mikro-orm/core';
|
|
1
|
+
import { ALIAS_REPLACEMENT, ARRAY_OPERATORS, raw, RawQueryFragment, Type, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { AbstractSqlPlatform } from '../../AbstractSqlPlatform.js';
|
|
3
3
|
import { PostgreSqlNativeQueryBuilder } from './PostgreSqlNativeQueryBuilder.js';
|
|
4
4
|
import { PostgreSqlSchemaHelper } from './PostgreSqlSchemaHelper.js';
|
|
5
5
|
import { PostgreSqlExceptionConverter } from './PostgreSqlExceptionConverter.js';
|
|
6
6
|
import { FullTextType } from './FullTextType.js';
|
|
7
7
|
export class BasePostgreSqlPlatform extends AbstractSqlPlatform {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
usesReturningStatement() {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
usesCascadeStatement() {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
supportsNativeEnums() {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
usesEnumCheckConstraints() {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
getEnumArrayCheckConstraintExpression(column, items) {
|
|
28
|
-
return `${this.quoteIdentifier(column)} <@ array[${items.map(item => `'${item}'::text`).join(', ')}]`;
|
|
29
|
-
}
|
|
30
|
-
supportsMaterializedViews() {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
supportsCustomPrimaryKeyNames() {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
getCurrentTimestampSQL(length) {
|
|
37
|
-
return `current_timestamp(${length})`;
|
|
38
|
-
}
|
|
39
|
-
getDateTimeTypeDeclarationSQL(column) {
|
|
40
|
-
/* v8 ignore next */
|
|
41
|
-
return 'timestamptz' + (column.length != null ? `(${column.length})` : '');
|
|
42
|
-
}
|
|
43
|
-
getDefaultDateTimeLength() {
|
|
44
|
-
return 6;
|
|
45
|
-
}
|
|
46
|
-
getTimeTypeDeclarationSQL() {
|
|
47
|
-
return 'time(0)';
|
|
48
|
-
}
|
|
49
|
-
getIntegerTypeDeclarationSQL(column) {
|
|
50
|
-
if (column.autoincrement && !column.generated) {
|
|
51
|
-
return 'serial';
|
|
52
|
-
}
|
|
53
|
-
return 'int';
|
|
54
|
-
}
|
|
55
|
-
getBigIntTypeDeclarationSQL(column) {
|
|
56
|
-
/* v8 ignore next */
|
|
57
|
-
if (column.autoincrement) {
|
|
58
|
-
return `bigserial`;
|
|
59
|
-
}
|
|
60
|
-
return 'bigint';
|
|
61
|
-
}
|
|
62
|
-
getTinyIntTypeDeclarationSQL(column) {
|
|
63
|
-
return 'smallint';
|
|
64
|
-
}
|
|
65
|
-
getUuidTypeDeclarationSQL(column) {
|
|
66
|
-
return `uuid`;
|
|
67
|
-
}
|
|
68
|
-
getFullTextWhereClause(prop) {
|
|
69
|
-
if (prop.customType instanceof FullTextType) {
|
|
70
|
-
return `:column: @@ plainto_tsquery('${prop.customType.regconfig}', :query)`;
|
|
8
|
+
schemaHelper = new PostgreSqlSchemaHelper(this);
|
|
9
|
+
exceptionConverter = new PostgreSqlExceptionConverter();
|
|
10
|
+
/** Maps JS runtime type names to PostgreSQL cast types for JSON property access. @internal */
|
|
11
|
+
#jsonTypeCasts = { number: 'float8', bigint: 'int8', boolean: 'bool' };
|
|
12
|
+
createNativeQueryBuilder() {
|
|
13
|
+
return new PostgreSqlNativeQueryBuilder(this);
|
|
71
14
|
}
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
if (/"(.*)"/.exec(v)) {
|
|
192
|
-
return v.substring(1, v.length - 1).replaceAll('\\"', '"');
|
|
193
|
-
}
|
|
194
|
-
return v;
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
getVarcharTypeDeclarationSQL(column) {
|
|
198
|
-
if (column.length === -1) {
|
|
199
|
-
return 'varchar';
|
|
200
|
-
}
|
|
201
|
-
return super.getVarcharTypeDeclarationSQL(column);
|
|
202
|
-
}
|
|
203
|
-
getCharTypeDeclarationSQL(column) {
|
|
204
|
-
if (column.length === -1) {
|
|
205
|
-
return 'char';
|
|
206
|
-
}
|
|
207
|
-
return super.getCharTypeDeclarationSQL(column);
|
|
208
|
-
}
|
|
209
|
-
getIntervalTypeDeclarationSQL(column) {
|
|
210
|
-
return 'interval' + (column.length != null ? `(${column.length})` : '');
|
|
211
|
-
}
|
|
212
|
-
getBlobDeclarationSQL() {
|
|
213
|
-
return 'bytea';
|
|
214
|
-
}
|
|
215
|
-
getJsonDeclarationSQL() {
|
|
216
|
-
return 'jsonb';
|
|
217
|
-
}
|
|
218
|
-
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
219
|
-
const first = path.shift();
|
|
220
|
-
const last = path.pop();
|
|
221
|
-
const root = this.quoteIdentifier(aliased ? `${ALIAS_REPLACEMENT}.${first}` : first);
|
|
222
|
-
type = typeof type === 'string' ? this.getMappedType(type).runtimeType : String(type);
|
|
223
|
-
const cast = key => raw(type in this.#jsonTypeCasts ? `(${key})::${this.#jsonTypeCasts[type]}` : key);
|
|
224
|
-
let lastOperator = '->>';
|
|
225
|
-
// force `->` for operator payloads with array values
|
|
226
|
-
if (
|
|
227
|
-
Utils.isPlainObject(value) &&
|
|
228
|
-
Object.keys(value).every(key => ARRAY_OPERATORS.includes(key) && Array.isArray(value[key]))
|
|
229
|
-
) {
|
|
230
|
-
lastOperator = '->';
|
|
231
|
-
}
|
|
232
|
-
if (path.length === 0) {
|
|
233
|
-
return cast(`${root}${lastOperator}'${last}'`);
|
|
234
|
-
}
|
|
235
|
-
return cast(`${root}->${path.map(a => this.quoteValue(a)).join('->')}${lastOperator}'${last}'`);
|
|
236
|
-
}
|
|
237
|
-
getJsonIndexDefinition(index) {
|
|
238
|
-
return index.columnNames.map(column => {
|
|
239
|
-
if (!column.includes('.')) {
|
|
240
|
-
return column;
|
|
241
|
-
}
|
|
242
|
-
const path = column.split('.');
|
|
243
|
-
const first = path.shift();
|
|
244
|
-
const last = path.pop();
|
|
245
|
-
if (path.length === 0) {
|
|
246
|
-
return `(${this.quoteIdentifier(first)}->>${this.quoteValue(last)})`;
|
|
247
|
-
}
|
|
248
|
-
return `(${this.quoteIdentifier(first)}->${path.map(c => this.quoteValue(c)).join('->')}->>${this.quoteValue(last)})`;
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
quoteIdentifier(id, quote = '"') {
|
|
252
|
-
if (RawQueryFragment.isKnownFragment(id)) {
|
|
253
|
-
return super.quoteIdentifier(id);
|
|
254
|
-
}
|
|
255
|
-
return `${quote}${id.toString().replace('.', `${quote}.${quote}`)}${quote}`;
|
|
256
|
-
}
|
|
257
|
-
pad(number, digits) {
|
|
258
|
-
return String(number).padStart(digits, '0');
|
|
259
|
-
}
|
|
260
|
-
/** @internal */
|
|
261
|
-
formatDate(date) {
|
|
262
|
-
if (this.timezone === 'Z') {
|
|
263
|
-
return date.toISOString();
|
|
264
|
-
}
|
|
265
|
-
let offset = -date.getTimezoneOffset();
|
|
266
|
-
let year = date.getFullYear();
|
|
267
|
-
const isBCYear = year < 1;
|
|
268
|
-
/* v8 ignore next */
|
|
269
|
-
if (isBCYear) {
|
|
270
|
-
year = Math.abs(year) + 1;
|
|
15
|
+
usesReturningStatement() {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
usesCascadeStatement() {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
supportsNativeEnums() {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
usesEnumCheckConstraints() {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
getEnumArrayCheckConstraintExpression(column, items) {
|
|
28
|
+
return `${this.quoteIdentifier(column)} <@ array[${items.map(item => `'${item}'::text`).join(', ')}]`;
|
|
29
|
+
}
|
|
30
|
+
supportsMaterializedViews() {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
supportsCustomPrimaryKeyNames() {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
getCurrentTimestampSQL(length) {
|
|
37
|
+
return `current_timestamp(${length})`;
|
|
38
|
+
}
|
|
39
|
+
getDateTimeTypeDeclarationSQL(column) {
|
|
40
|
+
/* v8 ignore next */
|
|
41
|
+
return 'timestamptz' + (column.length != null ? `(${column.length})` : '');
|
|
42
|
+
}
|
|
43
|
+
getDefaultDateTimeLength() {
|
|
44
|
+
return 6;
|
|
45
|
+
}
|
|
46
|
+
getTimeTypeDeclarationSQL() {
|
|
47
|
+
return 'time(0)';
|
|
48
|
+
}
|
|
49
|
+
getIntegerTypeDeclarationSQL(column) {
|
|
50
|
+
if (column.autoincrement && !column.generated) {
|
|
51
|
+
return 'serial';
|
|
52
|
+
}
|
|
53
|
+
return 'int';
|
|
54
|
+
}
|
|
55
|
+
getBigIntTypeDeclarationSQL(column) {
|
|
56
|
+
/* v8 ignore next */
|
|
57
|
+
if (column.autoincrement) {
|
|
58
|
+
return `bigserial`;
|
|
59
|
+
}
|
|
60
|
+
return 'bigint';
|
|
61
|
+
}
|
|
62
|
+
getTinyIntTypeDeclarationSQL(column) {
|
|
63
|
+
return 'smallint';
|
|
64
|
+
}
|
|
65
|
+
getUuidTypeDeclarationSQL(column) {
|
|
66
|
+
return `uuid`;
|
|
67
|
+
}
|
|
68
|
+
getFullTextWhereClause(prop) {
|
|
69
|
+
if (prop.customType instanceof FullTextType) {
|
|
70
|
+
return `:column: @@ plainto_tsquery('${prop.customType.regconfig}', :query)`;
|
|
71
|
+
}
|
|
72
|
+
/* v8 ignore next */
|
|
73
|
+
if (prop.columnTypes[0] === 'tsvector') {
|
|
74
|
+
return `:column: @@ plainto_tsquery('simple', :query)`;
|
|
75
|
+
}
|
|
76
|
+
return `to_tsvector('simple', :column:) @@ plainto_tsquery('simple', :query)`;
|
|
77
|
+
}
|
|
78
|
+
supportsCreatingFullTextIndex() {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
getFullTextIndexExpression(indexName, schemaName, tableName, columns) {
|
|
82
|
+
/* v8 ignore next */
|
|
83
|
+
const quotedTableName = this.quoteIdentifier(schemaName ? `${schemaName}.${tableName}` : tableName);
|
|
84
|
+
const quotedColumnNames = columns.map(c => this.quoteIdentifier(c.name));
|
|
85
|
+
const quotedIndexName = this.quoteIdentifier(indexName);
|
|
86
|
+
if (columns.length === 1 && columns[0].type === 'tsvector') {
|
|
87
|
+
return `create index ${quotedIndexName} on ${quotedTableName} using gin(${quotedColumnNames[0]})`;
|
|
88
|
+
}
|
|
89
|
+
return `create index ${quotedIndexName} on ${quotedTableName} using gin(to_tsvector('simple', ${quotedColumnNames.join(` || ' ' || `)}))`;
|
|
90
|
+
}
|
|
91
|
+
normalizeColumnType(type, options) {
|
|
92
|
+
const simpleType = this.extractSimpleType(type);
|
|
93
|
+
if (['int', 'int4', 'integer'].includes(simpleType)) {
|
|
94
|
+
return this.getIntegerTypeDeclarationSQL({});
|
|
95
|
+
}
|
|
96
|
+
if (['bigint', 'int8'].includes(simpleType)) {
|
|
97
|
+
return this.getBigIntTypeDeclarationSQL({});
|
|
98
|
+
}
|
|
99
|
+
if (['smallint', 'int2'].includes(simpleType)) {
|
|
100
|
+
return this.getSmallIntTypeDeclarationSQL({});
|
|
101
|
+
}
|
|
102
|
+
if (['boolean', 'bool'].includes(simpleType)) {
|
|
103
|
+
return this.getBooleanTypeDeclarationSQL();
|
|
104
|
+
}
|
|
105
|
+
if (['varchar', 'character varying'].includes(simpleType)) {
|
|
106
|
+
return this.getVarcharTypeDeclarationSQL(options);
|
|
107
|
+
}
|
|
108
|
+
if (['char', 'bpchar'].includes(simpleType)) {
|
|
109
|
+
return this.getCharTypeDeclarationSQL(options);
|
|
110
|
+
}
|
|
111
|
+
if (['decimal', 'numeric'].includes(simpleType)) {
|
|
112
|
+
return this.getDecimalTypeDeclarationSQL(options);
|
|
113
|
+
}
|
|
114
|
+
if (['interval'].includes(simpleType)) {
|
|
115
|
+
return this.getIntervalTypeDeclarationSQL(options);
|
|
116
|
+
}
|
|
117
|
+
return super.normalizeColumnType(type, options);
|
|
118
|
+
}
|
|
119
|
+
getMappedType(type) {
|
|
120
|
+
switch (this.extractSimpleType(type)) {
|
|
121
|
+
case 'tsvector':
|
|
122
|
+
return Type.getType(FullTextType);
|
|
123
|
+
default:
|
|
124
|
+
return super.getMappedType(type);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
getRegExpOperator(val, flags) {
|
|
128
|
+
/* v8 ignore next */
|
|
129
|
+
if ((val instanceof RegExp && val.flags.includes('i')) || flags?.includes('i')) {
|
|
130
|
+
return '~*';
|
|
131
|
+
}
|
|
132
|
+
return '~';
|
|
271
133
|
}
|
|
272
|
-
const datePart = `${this.pad(year, 4)}-${this.pad(date.getMonth() + 1, 2)}-${this.pad(date.getDate(), 2)}`;
|
|
273
|
-
const timePart = `${this.pad(date.getHours(), 2)}:${this.pad(date.getMinutes(), 2)}:${this.pad(date.getSeconds(), 2)}.${this.pad(date.getMilliseconds(), 3)}`;
|
|
274
|
-
let ret = `${datePart}T${timePart}`;
|
|
275
134
|
/* v8 ignore next */
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
135
|
+
getRegExpValue(val) {
|
|
136
|
+
if (val.flags.includes('i')) {
|
|
137
|
+
return { $re: val.source, $flags: val.flags };
|
|
138
|
+
}
|
|
139
|
+
return { $re: val.source };
|
|
140
|
+
}
|
|
141
|
+
isBigIntProperty(prop) {
|
|
142
|
+
return super.isBigIntProperty(prop) || ['bigserial', 'int8'].includes(prop.columnTypes?.[0]);
|
|
143
|
+
}
|
|
144
|
+
getArrayDeclarationSQL() {
|
|
145
|
+
return 'text[]';
|
|
146
|
+
}
|
|
147
|
+
getFloatDeclarationSQL() {
|
|
148
|
+
return 'real';
|
|
149
|
+
}
|
|
150
|
+
getDoubleDeclarationSQL() {
|
|
151
|
+
return 'double precision';
|
|
152
|
+
}
|
|
153
|
+
getEnumTypeDeclarationSQL(column) {
|
|
154
|
+
/* v8 ignore next */
|
|
155
|
+
if (column.nativeEnumName) {
|
|
156
|
+
return column.nativeEnumName;
|
|
157
|
+
}
|
|
158
|
+
if (column.items?.every(item => typeof item === 'string')) {
|
|
159
|
+
return 'text';
|
|
160
|
+
}
|
|
161
|
+
return `smallint`;
|
|
162
|
+
}
|
|
163
|
+
supportsMultipleStatements() {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
getBeginTransactionSQL(options) {
|
|
167
|
+
if (options?.isolationLevel || options?.readOnly) {
|
|
168
|
+
let sql = 'start transaction';
|
|
169
|
+
sql += options.isolationLevel ? ` isolation level ${options.isolationLevel}` : '';
|
|
170
|
+
sql += options.readOnly ? ` read only` : '';
|
|
171
|
+
return [sql];
|
|
172
|
+
}
|
|
173
|
+
return ['begin'];
|
|
174
|
+
}
|
|
175
|
+
marshallArray(values) {
|
|
176
|
+
const quote = (v) => (v === '' || /["{},\\]/.exec(v) ? JSON.stringify(v) : v);
|
|
177
|
+
return `{${values.map(v => quote('' + v)).join(',')}}`;
|
|
281
178
|
}
|
|
282
|
-
ret += this.pad(Math.floor(offset / 60), 2) + ':' + this.pad(offset % 60, 2);
|
|
283
179
|
/* v8 ignore next */
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
180
|
+
unmarshallArray(value) {
|
|
181
|
+
if (value === '{}') {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
return value
|
|
185
|
+
.substring(1, value.length - 1)
|
|
186
|
+
.split(',')
|
|
187
|
+
.map(v => {
|
|
188
|
+
if (v === `""`) {
|
|
189
|
+
return '';
|
|
190
|
+
}
|
|
191
|
+
if (/"(.*)"/.exec(v)) {
|
|
192
|
+
return v.substring(1, v.length - 1).replaceAll('\\"', '"');
|
|
193
|
+
}
|
|
194
|
+
return v;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
getVarcharTypeDeclarationSQL(column) {
|
|
198
|
+
if (column.length === -1) {
|
|
199
|
+
return 'varchar';
|
|
200
|
+
}
|
|
201
|
+
return super.getVarcharTypeDeclarationSQL(column);
|
|
202
|
+
}
|
|
203
|
+
getCharTypeDeclarationSQL(column) {
|
|
204
|
+
if (column.length === -1) {
|
|
205
|
+
return 'char';
|
|
206
|
+
}
|
|
207
|
+
return super.getCharTypeDeclarationSQL(column);
|
|
208
|
+
}
|
|
209
|
+
getIntervalTypeDeclarationSQL(column) {
|
|
210
|
+
return 'interval' + (column.length != null ? `(${column.length})` : '');
|
|
211
|
+
}
|
|
212
|
+
getBlobDeclarationSQL() {
|
|
213
|
+
return 'bytea';
|
|
214
|
+
}
|
|
215
|
+
getJsonDeclarationSQL() {
|
|
216
|
+
return 'jsonb';
|
|
217
|
+
}
|
|
218
|
+
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
219
|
+
const first = path.shift();
|
|
220
|
+
const last = path.pop();
|
|
221
|
+
const root = this.quoteIdentifier(aliased ? `${ALIAS_REPLACEMENT}.${first}` : first);
|
|
222
|
+
type = typeof type === 'string' ? this.getMappedType(type).runtimeType : String(type);
|
|
223
|
+
const cast = (key) => raw(type in this.#jsonTypeCasts ? `(${key})::${this.#jsonTypeCasts[type]}` : key);
|
|
224
|
+
let lastOperator = '->>';
|
|
225
|
+
// force `->` for operator payloads with array values
|
|
226
|
+
if (Utils.isPlainObject(value) &&
|
|
227
|
+
Object.keys(value).every(key => ARRAY_OPERATORS.includes(key) && Array.isArray(value[key]))) {
|
|
228
|
+
lastOperator = '->';
|
|
229
|
+
}
|
|
230
|
+
if (path.length === 0) {
|
|
231
|
+
return cast(`${root}${lastOperator}'${last}'`);
|
|
232
|
+
}
|
|
233
|
+
return cast(`${root}->${path.map(a => this.quoteValue(a)).join('->')}${lastOperator}'${last}'`);
|
|
234
|
+
}
|
|
235
|
+
getJsonIndexDefinition(index) {
|
|
236
|
+
return index.columnNames.map(column => {
|
|
237
|
+
if (!column.includes('.')) {
|
|
238
|
+
return column;
|
|
239
|
+
}
|
|
240
|
+
const path = column.split('.');
|
|
241
|
+
const first = path.shift();
|
|
242
|
+
const last = path.pop();
|
|
243
|
+
if (path.length === 0) {
|
|
244
|
+
return `(${this.quoteIdentifier(first)}->>${this.quoteValue(last)})`;
|
|
245
|
+
}
|
|
246
|
+
return `(${this.quoteIdentifier(first)}->${path.map(c => this.quoteValue(c)).join('->')}->>${this.quoteValue(last)})`;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
quoteIdentifier(id, quote = '"') {
|
|
250
|
+
if (RawQueryFragment.isKnownFragment(id)) {
|
|
251
|
+
return super.quoteIdentifier(id);
|
|
252
|
+
}
|
|
253
|
+
return `${quote}${id.toString().replace('.', `${quote}.${quote}`)}${quote}`;
|
|
254
|
+
}
|
|
255
|
+
pad(number, digits) {
|
|
256
|
+
return String(number).padStart(digits, '0');
|
|
257
|
+
}
|
|
258
|
+
/** @internal */
|
|
259
|
+
formatDate(date) {
|
|
260
|
+
if (this.timezone === 'Z') {
|
|
261
|
+
return date.toISOString();
|
|
262
|
+
}
|
|
263
|
+
let offset = -date.getTimezoneOffset();
|
|
264
|
+
let year = date.getFullYear();
|
|
265
|
+
const isBCYear = year < 1;
|
|
266
|
+
/* v8 ignore next */
|
|
267
|
+
if (isBCYear) {
|
|
268
|
+
year = Math.abs(year) + 1;
|
|
269
|
+
}
|
|
270
|
+
const datePart = `${this.pad(year, 4)}-${this.pad(date.getMonth() + 1, 2)}-${this.pad(date.getDate(), 2)}`;
|
|
271
|
+
const timePart = `${this.pad(date.getHours(), 2)}:${this.pad(date.getMinutes(), 2)}:${this.pad(date.getSeconds(), 2)}.${this.pad(date.getMilliseconds(), 3)}`;
|
|
272
|
+
let ret = `${datePart}T${timePart}`;
|
|
273
|
+
/* v8 ignore next */
|
|
274
|
+
if (offset < 0) {
|
|
275
|
+
ret += '-';
|
|
276
|
+
offset *= -1;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
ret += '+';
|
|
280
|
+
}
|
|
281
|
+
ret += this.pad(Math.floor(offset / 60), 2) + ':' + this.pad(offset % 60, 2);
|
|
282
|
+
/* v8 ignore next */
|
|
283
|
+
if (isBCYear) {
|
|
284
|
+
ret += ' BC';
|
|
285
|
+
}
|
|
286
|
+
return ret;
|
|
287
|
+
}
|
|
288
|
+
indexForeignKeys() {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
getDefaultMappedType(type) {
|
|
292
|
+
const normalizedType = this.extractSimpleType(type);
|
|
293
|
+
const map = {
|
|
294
|
+
int2: 'smallint',
|
|
295
|
+
smallserial: 'smallint',
|
|
296
|
+
int: 'integer',
|
|
297
|
+
int4: 'integer',
|
|
298
|
+
serial: 'integer',
|
|
299
|
+
serial4: 'integer',
|
|
300
|
+
int8: 'bigint',
|
|
301
|
+
bigserial: 'bigint',
|
|
302
|
+
serial8: 'bigint',
|
|
303
|
+
numeric: 'decimal',
|
|
304
|
+
bool: 'boolean',
|
|
305
|
+
real: 'float',
|
|
306
|
+
float4: 'float',
|
|
307
|
+
float8: 'double',
|
|
308
|
+
timestamp: 'datetime',
|
|
309
|
+
timestamptz: 'datetime',
|
|
310
|
+
bytea: 'blob',
|
|
311
|
+
jsonb: 'json',
|
|
312
|
+
'character varying': 'varchar',
|
|
313
|
+
bpchar: 'character',
|
|
314
|
+
};
|
|
315
|
+
return super.getDefaultMappedType(map[normalizedType] ?? type);
|
|
316
|
+
}
|
|
317
|
+
supportsSchemas() {
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
getDefaultSchemaName() {
|
|
321
|
+
return 'public';
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Returns the default name of index for the given columns
|
|
325
|
+
* cannot go past 63 character length for identifiers in MySQL
|
|
326
|
+
*/
|
|
327
|
+
getIndexName(tableName, columns, type) {
|
|
328
|
+
const indexName = super.getIndexName(tableName, columns, type);
|
|
329
|
+
if (indexName.length > 63) {
|
|
330
|
+
const suffix = type === 'primary' ? 'pkey' : type;
|
|
331
|
+
return `${indexName.substring(0, 55 - type.length)}_${Utils.hash(indexName, 5)}_${suffix}`;
|
|
332
|
+
}
|
|
333
|
+
return indexName;
|
|
334
|
+
}
|
|
335
|
+
getDefaultPrimaryName(tableName, columns) {
|
|
336
|
+
const indexName = `${tableName}_pkey`;
|
|
337
|
+
if (indexName.length > 63) {
|
|
338
|
+
return `${indexName.substring(0, 55 - 'pkey'.length)}_${Utils.hash(indexName, 5)}_pkey`;
|
|
339
|
+
}
|
|
340
|
+
return indexName;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* @inheritDoc
|
|
344
|
+
*/
|
|
345
|
+
castColumn(prop) {
|
|
346
|
+
switch (prop?.columnTypes?.[0]) {
|
|
347
|
+
case this.getUuidTypeDeclarationSQL({}):
|
|
348
|
+
return '::text';
|
|
349
|
+
case this.getBooleanTypeDeclarationSQL():
|
|
350
|
+
return '::int';
|
|
351
|
+
default:
|
|
352
|
+
return '';
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
getJsonArrayFromSQL(column, alias, _properties) {
|
|
356
|
+
return `jsonb_array_elements(${column}) as ${this.quoteIdentifier(alias)}`;
|
|
357
|
+
}
|
|
358
|
+
getJsonArrayElementPropertySQL(alias, property, type) {
|
|
359
|
+
const expr = `${this.quoteIdentifier(alias)}->>${this.quoteValue(property)}`;
|
|
360
|
+
return type in this.#jsonTypeCasts ? `(${expr})::${this.#jsonTypeCasts[type]}` : expr;
|
|
361
|
+
}
|
|
362
|
+
getDefaultClientUrl() {
|
|
363
|
+
return 'postgresql://postgres@127.0.0.1:5432';
|
|
364
|
+
}
|
|
366
365
|
}
|