@mikro-orm/sql 7.0.0-dev.302 → 7.0.0-dev.304
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/AbstractSqlDriver.js +1 -1
- package/AbstractSqlPlatform.js +1 -1
- package/dialects/mysql/MySqlSchemaHelper.js +2 -2
- package/dialects/postgresql/BasePostgreSqlPlatform.js +2 -2
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +10 -10
- package/dialects/sqlite/SqliteSchemaHelper.js +12 -8
- package/index.d.ts +1 -1
- package/index.js +0 -1
- package/package.json +2 -2
- package/query/ObjectCriteriaNode.js +1 -1
- package/query/QueryBuilder.js +3 -3
- package/query/QueryBuilderHelper.js +2 -2
- package/schema/DatabaseTable.js +2 -2
- package/schema/SchemaComparator.js +2 -2
- package/schema/SchemaHelper.js +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
package/AbstractSqlDriver.js
CHANGED
|
@@ -894,7 +894,7 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
894
894
|
const pks = Utils.flatten(pkProps.map(pk => meta.properties[pk].fieldNames));
|
|
895
895
|
sql +=
|
|
896
896
|
pks.length > 1
|
|
897
|
-
? `(${pks.map(pk =>
|
|
897
|
+
? `(${pks.map(pk => this.platform.quoteIdentifier(pk)).join(', ')})`
|
|
898
898
|
: this.platform.quoteIdentifier(pks[0]);
|
|
899
899
|
const conds = where.map(cond => {
|
|
900
900
|
if (Utils.isPlainObject(cond) && Utils.getObjectKeysSize(cond) === 1) {
|
package/AbstractSqlPlatform.js
CHANGED
|
@@ -64,7 +64,7 @@ export class AbstractSqlPlatform extends Platform {
|
|
|
64
64
|
}
|
|
65
65
|
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
66
66
|
const [a, ...b] = path;
|
|
67
|
-
const quoteKey = (key) => (
|
|
67
|
+
const quoteKey = (key) => (/^[a-z]\w*$/i.exec(key) ? key : `"${key}"`);
|
|
68
68
|
if (aliased) {
|
|
69
69
|
return raw(alias => `json_extract(${this.quoteIdentifier(`${alias}.${a}`)}, '$.${b.map(quoteKey).join('.')}')`);
|
|
70
70
|
}
|
|
@@ -46,7 +46,7 @@ export class MySqlSchemaHelper extends SchemaHelper {
|
|
|
46
46
|
const createView = await connection.execute(`show create view \`${view.view_name}\``);
|
|
47
47
|
if (createView[0]?.['Create View']) {
|
|
48
48
|
// Extract SELECT statement from CREATE VIEW ... AS SELECT ...
|
|
49
|
-
const match = createView[0]['Create View']
|
|
49
|
+
const match = /\bAS\s+(.+)$/is.exec(createView[0]['Create View']);
|
|
50
50
|
definition = match?.[1]?.trim();
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -339,7 +339,7 @@ export class MySqlSchemaHelper extends SchemaHelper {
|
|
|
339
339
|
o[item.table_name][item.column_name] = item.column_type
|
|
340
340
|
.match(/enum\((.*)\)/)[1]
|
|
341
341
|
.split(',')
|
|
342
|
-
.map((item) =>
|
|
342
|
+
.map((item) => /'(.*)'/.exec(item)[1]);
|
|
343
343
|
return o;
|
|
344
344
|
}, {});
|
|
345
345
|
}
|
|
@@ -168,7 +168,7 @@ export class BasePostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
168
168
|
return ['begin'];
|
|
169
169
|
}
|
|
170
170
|
marshallArray(values) {
|
|
171
|
-
const quote = (v) => (v === '' ||
|
|
171
|
+
const quote = (v) => (v === '' || /["{},\\]/.exec(v) ? JSON.stringify(v) : v);
|
|
172
172
|
return `{${values.map(v => quote('' + v)).join(',')}}`;
|
|
173
173
|
}
|
|
174
174
|
/* v8 ignore next */
|
|
@@ -183,7 +183,7 @@ export class BasePostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
183
183
|
if (v === `""`) {
|
|
184
184
|
return '';
|
|
185
185
|
}
|
|
186
|
-
if (
|
|
186
|
+
if (/"(.*)"/.exec(v)) {
|
|
187
187
|
return v.substring(1, v.length - 1).replaceAll('\\"', '"');
|
|
188
188
|
}
|
|
189
189
|
return v;
|
|
@@ -152,7 +152,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
152
152
|
if (index.condeferrable) {
|
|
153
153
|
indexDef.deferMode = index.condeferred ? DeferMode.INITIALLY_DEFERRED : DeferMode.INITIALLY_IMMEDIATE;
|
|
154
154
|
}
|
|
155
|
-
if (index.index_def.some((col) =>
|
|
155
|
+
if (index.index_def.some((col) => /[(): ,"'`]/.exec(col)) || index.expression?.match(/ where /i)) {
|
|
156
156
|
indexDef.expression = index.expression;
|
|
157
157
|
}
|
|
158
158
|
if (index.deferrable) {
|
|
@@ -190,7 +190,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
190
190
|
// Extract just the column list from the expression (between first parens after USING)
|
|
191
191
|
// Pattern: ... USING method (...columns...) [INCLUDE (...)] [WHERE ...]
|
|
192
192
|
// Note: pg_get_indexdef always returns a valid expression with USING clause
|
|
193
|
-
const usingMatch =
|
|
193
|
+
const usingMatch = /using\s+\w+\s*\(/i.exec(expression);
|
|
194
194
|
const startIdx = usingMatch.index + usingMatch[0].length - 1; // Position of opening (
|
|
195
195
|
const columnsStr = this.extractParenthesizedContent(expression, startIdx);
|
|
196
196
|
// Use the column names from columnDefs and find their modifiers in the expression
|
|
@@ -209,12 +209,12 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
209
209
|
result.sort = 'DESC';
|
|
210
210
|
}
|
|
211
211
|
// Extract NULLS ordering
|
|
212
|
-
const nullsMatch =
|
|
212
|
+
const nullsMatch = /nulls\s+(first|last)/i.exec(modifiers);
|
|
213
213
|
if (nullsMatch) {
|
|
214
214
|
result.nulls = nullsMatch[1].toUpperCase();
|
|
215
215
|
}
|
|
216
216
|
// Extract collation
|
|
217
|
-
const collateMatch =
|
|
217
|
+
const collateMatch = /collate\s+"?([^"\s,)]+)"?/i.exec(modifiers);
|
|
218
218
|
if (collateMatch) {
|
|
219
219
|
result.collation = collateMatch[1];
|
|
220
220
|
}
|
|
@@ -333,7 +333,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
333
333
|
}
|
|
334
334
|
seen.add(dedupeKey);
|
|
335
335
|
ret[key] ??= [];
|
|
336
|
-
const m =
|
|
336
|
+
const m = /^check \(\((.*)\)\)$/is.exec(check.expression);
|
|
337
337
|
const def = m?.[1].replace(/\((.*?)\)::\w+/g, '$1');
|
|
338
338
|
ret[key].push({
|
|
339
339
|
name: check.name,
|
|
@@ -362,7 +362,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
362
362
|
const allFks = await connection.execute(sql);
|
|
363
363
|
const ret = {};
|
|
364
364
|
function mapReferentialIntegrity(value, def) {
|
|
365
|
-
const match = ['n', 'd'].includes(value) &&
|
|
365
|
+
const match = ['n', 'd'].includes(value) && /ON DELETE (SET (NULL|DEFAULT) \(.*?\))/.exec(def);
|
|
366
366
|
if (match) {
|
|
367
367
|
return match[1];
|
|
368
368
|
}
|
|
@@ -465,10 +465,10 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
465
465
|
let items;
|
|
466
466
|
/* v8 ignore next */
|
|
467
467
|
if (m3) {
|
|
468
|
-
items = m3.map((item) =>
|
|
468
|
+
items = m3.map((item) => /^\(?'(.*)'/.exec(item.trim())?.[1]);
|
|
469
469
|
}
|
|
470
470
|
else {
|
|
471
|
-
items = m2[1].split(',').map((item) =>
|
|
471
|
+
items = m2[1].split(',').map((item) => /^\(?'(.*)'/.exec(item.trim())?.[1]);
|
|
472
472
|
}
|
|
473
473
|
items = items.filter(item => item !== undefined);
|
|
474
474
|
if (items.length > 0) {
|
|
@@ -605,7 +605,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
605
605
|
if (!defaultValue || typeof defaultValue !== 'string') {
|
|
606
606
|
return super.normalizeDefaultValue(defaultValue, length, PostgreSqlSchemaHelper.DEFAULT_VALUES);
|
|
607
607
|
}
|
|
608
|
-
const match =
|
|
608
|
+
const match = /^'(.*)'::(.*)$/.exec(defaultValue);
|
|
609
609
|
if (match) {
|
|
610
610
|
if (match[2] === 'integer') {
|
|
611
611
|
return +match[1];
|
|
@@ -723,7 +723,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
723
723
|
order by pgc.conname`;
|
|
724
724
|
}
|
|
725
725
|
inferLengthFromColumnType(type) {
|
|
726
|
-
const match =
|
|
726
|
+
const match = /^(\w+(?:\s+\w+)*)\s*(?:\(\s*(\d+)\s*\)|$)/.exec(type);
|
|
727
727
|
if (!match) {
|
|
728
728
|
return;
|
|
729
729
|
}
|
|
@@ -220,7 +220,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
220
220
|
const columns = {};
|
|
221
221
|
const constraints = [];
|
|
222
222
|
// extract all columns definitions
|
|
223
|
-
let columnsDef =
|
|
223
|
+
let columnsDef = new RegExp(`create table [\`"']?.*?[\`"']? \\((.*)\\)`, 'i').exec(sql.replaceAll('\n', ''))?.[1];
|
|
224
224
|
/* v8 ignore next */
|
|
225
225
|
if (columnsDef) {
|
|
226
226
|
if (columnsDef.includes(', constraint ')) {
|
|
@@ -230,7 +230,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
230
230
|
for (let i = cols.length - 1; i >= 0; i--) {
|
|
231
231
|
const col = cols[i];
|
|
232
232
|
const re = ` *, *[\`"']?${col.name}[\`"']? (.*)`;
|
|
233
|
-
const columnDef =
|
|
233
|
+
const columnDef = new RegExp(re, 'i').exec(columnsDef);
|
|
234
234
|
if (columnDef) {
|
|
235
235
|
columns[col.name] = { name: col.name, definition: columnDef[1] };
|
|
236
236
|
columnsDef = columnsDef.substring(0, columnDef.index);
|
|
@@ -260,7 +260,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
260
260
|
* Extracts the SELECT part from a CREATE VIEW statement.
|
|
261
261
|
*/
|
|
262
262
|
extractViewDefinition(viewDefinition) {
|
|
263
|
-
const match =
|
|
263
|
+
const match = /create\s+view\s+[`"']?\w+[`"']?\s+as\s+(.*)/i.exec(viewDefinition);
|
|
264
264
|
/* v8 ignore next - fallback for non-standard view definitions */
|
|
265
265
|
return match ? match[1] : viewDefinition;
|
|
266
266
|
}
|
|
@@ -307,7 +307,11 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
307
307
|
return null;
|
|
308
308
|
}
|
|
309
309
|
// simple values that are returned as-is from pragma (no wrapping needed)
|
|
310
|
-
if (/^-?\d/.test(value) ||
|
|
310
|
+
if (/^-?\d/.test(value) ||
|
|
311
|
+
/^[xX]'/.test(value) ||
|
|
312
|
+
value.startsWith("'") ||
|
|
313
|
+
value.startsWith('"') ||
|
|
314
|
+
value.startsWith('(')) {
|
|
311
315
|
return value;
|
|
312
316
|
}
|
|
313
317
|
const lower = value.toLowerCase();
|
|
@@ -325,10 +329,10 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
325
329
|
return checkConstraints.reduce((o, item) => {
|
|
326
330
|
// check constraints are defined as (note that last closing paren is missing):
|
|
327
331
|
// `type` text check (`type` in ('local', 'global')
|
|
328
|
-
const match =
|
|
332
|
+
const match = /[`["']([^`\]"']+)[`\]"'] text check \(.* \((.*)\)/i.exec(item);
|
|
329
333
|
/* v8 ignore next */
|
|
330
334
|
if (match) {
|
|
331
|
-
o[match[1]] = match[2].split(',').map((item) =>
|
|
335
|
+
o[match[1]] = match[2].split(',').map((item) => /^\(?'(.*)'/.exec(item.trim())[1]);
|
|
332
336
|
}
|
|
333
337
|
return o;
|
|
334
338
|
}, {});
|
|
@@ -371,7 +375,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
371
375
|
const checks = [];
|
|
372
376
|
for (const key of Object.keys(columns)) {
|
|
373
377
|
const column = columns[key];
|
|
374
|
-
const expression =
|
|
378
|
+
const expression = / (check \((.*)\))/i.exec(column.definition);
|
|
375
379
|
if (expression) {
|
|
376
380
|
checks.push({
|
|
377
381
|
name: this.platform.getConfig().getNamingStrategy().indexName(tableName, [column.name], 'check'),
|
|
@@ -382,7 +386,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
382
386
|
}
|
|
383
387
|
}
|
|
384
388
|
for (const constraint of constraints) {
|
|
385
|
-
const expression =
|
|
389
|
+
const expression = /constraint *[`"']?(.*?)[`"']? * (check \((.*)\))/i.exec(constraint);
|
|
386
390
|
if (expression) {
|
|
387
391
|
checks.push({
|
|
388
392
|
name: expression[1],
|
package/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export * from './query/index.js';
|
|
|
13
13
|
export { raw } from './query/index.js';
|
|
14
14
|
export * from './schema/index.js';
|
|
15
15
|
export * from './dialects/index.js';
|
|
16
|
-
export * from './typings.js';
|
|
16
|
+
export type * from './typings.js';
|
|
17
17
|
export * from './plugin/index.js';
|
|
18
18
|
export { SqlEntityManager as EntityManager } from './SqlEntityManager.js';
|
|
19
19
|
export { SqlEntityRepository as EntityRepository } from './SqlEntityRepository.js';
|
package/index.js
CHANGED
|
@@ -13,7 +13,6 @@ export * from './query/index.js';
|
|
|
13
13
|
export { raw } from './query/index.js';
|
|
14
14
|
export * from './schema/index.js';
|
|
15
15
|
export * from './dialects/index.js';
|
|
16
|
-
export * from './typings.js';
|
|
17
16
|
export * from './plugin/index.js';
|
|
18
17
|
export { SqlEntityManager as EntityManager } from './SqlEntityManager.js';
|
|
19
18
|
export { SqlEntityRepository as EntityRepository } from './SqlEntityRepository.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.0.0-dev.
|
|
3
|
+
"version": "7.0.0-dev.304",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^6.6.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.0.0-dev.304"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.js
CHANGED
|
@@ -117,7 +117,7 @@ export class QueryBuilder {
|
|
|
117
117
|
}
|
|
118
118
|
return f;
|
|
119
119
|
}
|
|
120
|
-
const asMatch =
|
|
120
|
+
const asMatch = FIELD_ALIAS_RE.exec(f);
|
|
121
121
|
if (asMatch) {
|
|
122
122
|
return `${this.resolveNestedPath(asMatch[1].trim())} as ${asMatch[2]}`;
|
|
123
123
|
}
|
|
@@ -511,7 +511,7 @@ export class QueryBuilder {
|
|
|
511
511
|
const aliases = new Set();
|
|
512
512
|
for (const field of this._fields ?? []) {
|
|
513
513
|
if (typeof field === 'string') {
|
|
514
|
-
const m =
|
|
514
|
+
const m = FIELD_ALIAS_RE.exec(field);
|
|
515
515
|
if (m) {
|
|
516
516
|
aliases.add(m[2]);
|
|
517
517
|
}
|
|
@@ -1366,7 +1366,7 @@ export class QueryBuilder {
|
|
|
1366
1366
|
// Strip 'as alias' suffix if present — the alias is passed to mapper at the end
|
|
1367
1367
|
let field = originalField;
|
|
1368
1368
|
let customAlias;
|
|
1369
|
-
const asMatch =
|
|
1369
|
+
const asMatch = FIELD_ALIAS_RE.exec(originalField);
|
|
1370
1370
|
if (asMatch) {
|
|
1371
1371
|
field = asMatch[1].trim();
|
|
1372
1372
|
customAlias = asMatch[2];
|
|
@@ -346,7 +346,7 @@ export class QueryBuilderHelper {
|
|
|
346
346
|
return false;
|
|
347
347
|
}
|
|
348
348
|
// when including the opening bracket/paren we consider it complex
|
|
349
|
-
return
|
|
349
|
+
return !/[{[(]/.exec(re.source);
|
|
350
350
|
}
|
|
351
351
|
getRegExpParam(re) {
|
|
352
352
|
const value = re.source
|
|
@@ -806,7 +806,7 @@ export class QueryBuilderHelper {
|
|
|
806
806
|
return { sql: `(${parts.join(' or ')})`, params };
|
|
807
807
|
}
|
|
808
808
|
isPrefixed(field) {
|
|
809
|
-
return
|
|
809
|
+
return !!/[\w`"[\]]+\./.exec(field);
|
|
810
810
|
}
|
|
811
811
|
fieldName(field, alias, always, idx = 0) {
|
|
812
812
|
const prop = this.getProperty(field, alias);
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -62,7 +62,7 @@ export class DatabaseTable {
|
|
|
62
62
|
const type = prop.enum ? 'enum' : prop.columnTypes[idx];
|
|
63
63
|
const mappedType = this.platform.getMappedType(type);
|
|
64
64
|
if (mappedType instanceof DecimalType) {
|
|
65
|
-
const match =
|
|
65
|
+
const match = /\w+\((\d+), ?(\d+)\)/.exec(prop.columnTypes[idx]);
|
|
66
66
|
/* v8 ignore next */
|
|
67
67
|
if (match) {
|
|
68
68
|
prop.precision ??= +match[1];
|
|
@@ -755,7 +755,7 @@ export class DatabaseTable {
|
|
|
755
755
|
return +defaultValue;
|
|
756
756
|
}
|
|
757
757
|
// unquote string defaults if `raw = false`
|
|
758
|
-
const match = ('' + val)
|
|
758
|
+
const match = /^'(.*)'$/.exec('' + val);
|
|
759
759
|
if (!raw && match) {
|
|
760
760
|
return match[1];
|
|
761
761
|
}
|
|
@@ -704,8 +704,8 @@ export class SchemaComparator {
|
|
|
704
704
|
return from.default == to.default; // == intentionally
|
|
705
705
|
}
|
|
706
706
|
mapColumnToProperty(column) {
|
|
707
|
-
const length =
|
|
708
|
-
const match =
|
|
707
|
+
const length = /\w+\((\d+)\)/.exec(column.type);
|
|
708
|
+
const match = /\w+\((\d+), ?(\d+)\)/.exec(column.type);
|
|
709
709
|
return {
|
|
710
710
|
fieldNames: [column.name],
|
|
711
711
|
columnTypes: [column.type],
|
package/schema/SchemaHelper.js
CHANGED