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