@mikro-orm/sql 7.2.7-dev.9 → 7.2.8-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/dialects/postgresql/PostgreSqlSchemaHelper.js +24 -7
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +1 -0
- package/dialects/sqlite/SqliteSchemaHelper.js +3 -0
- package/package.json +3 -3
- package/query/NativeQueryBuilder.js +7 -1
- package/query/QueryBuilder.js +4 -2
- package/query/QueryBuilderHelper.js +2 -2
- package/schema/SchemaHelper.d.ts +2 -0
- package/schema/SchemaHelper.js +4 -0
|
@@ -15,19 +15,35 @@ function normalizeIntervalLiteral(literal) {
|
|
|
15
15
|
// `[field, factor]` into the months, days and microseconds triple PostgreSQL stores an interval as
|
|
16
16
|
const units = {
|
|
17
17
|
year: [0, 12],
|
|
18
|
+
yr: [0, 12],
|
|
19
|
+
y: [0, 12],
|
|
18
20
|
month: [0, 1],
|
|
19
21
|
mon: [0, 1],
|
|
20
22
|
week: [1, 7],
|
|
23
|
+
w: [1, 7],
|
|
21
24
|
day: [1, 1],
|
|
25
|
+
d: [1, 1],
|
|
22
26
|
hour: [2, 3_600_000_000],
|
|
27
|
+
hr: [2, 3_600_000_000],
|
|
28
|
+
h: [2, 3_600_000_000],
|
|
23
29
|
minute: [2, 60_000_000],
|
|
30
|
+
min: [2, 60_000_000],
|
|
31
|
+
m: [2, 60_000_000],
|
|
24
32
|
second: [2, 1_000_000],
|
|
33
|
+
sec: [2, 1_000_000],
|
|
34
|
+
s: [2, 1_000_000],
|
|
35
|
+
millisecond: [2, 1_000],
|
|
36
|
+
msec: [2, 1_000],
|
|
37
|
+
ms: [2, 1_000],
|
|
38
|
+
microsecond: [2, 1],
|
|
39
|
+
usec: [2, 1],
|
|
40
|
+
us: [2, 1],
|
|
25
41
|
};
|
|
26
42
|
const parts = [0, 0, 0];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const [field, factor] = units[unit];
|
|
43
|
+
// longer spellings first, so `ms`/`msec` are not read as `m` + plural `s`
|
|
44
|
+
const unitRe = /(\d+(?:\.\d+)?) *(milliseconds?|microseconds?|msecs?|usecs?|years?|months?|mons?|weeks?|days?|hours?|minutes?|seconds?|yrs?|hrs?|mins?|secs?|ms|us|[ywdhms])\b/g;
|
|
45
|
+
const rest = literal.toLowerCase().replace(unitRe, (_, qty, unit) => {
|
|
46
|
+
const [field, factor] = units[unit] ?? units[unit.slice(0, -1)];
|
|
31
47
|
parts[field] += +qty * factor;
|
|
32
48
|
return '';
|
|
33
49
|
});
|
|
@@ -1271,9 +1287,10 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
1271
1287
|
return `comment on table ${table.getQuotedName()} is ${this.platform.quoteValue(comment ?? '')}`;
|
|
1272
1288
|
}
|
|
1273
1289
|
normalizeExpression(expr) {
|
|
1274
|
-
return expr.replace(/\binterval\s*'([^']*)'|'([^']*)'\s*::\s*interval\b/gi, (
|
|
1275
|
-
|
|
1276
|
-
|
|
1290
|
+
return expr.replace(/\binterval\s*'([^']*)'|'([^']*)'\s*::\s*interval\b/gi, (_, typed, cast) => {
|
|
1291
|
+
// `interval 'x'` and `'x'::interval` are the same literal and PostgreSQL always prints the cast form
|
|
1292
|
+
const literal = typed ?? cast;
|
|
1293
|
+
return `'${normalizeIntervalLiteral(literal) ?? literal}'::interval`;
|
|
1277
1294
|
});
|
|
1278
1295
|
}
|
|
1279
1296
|
normalizeDefaultValue(defaultValue, length) {
|
|
@@ -8,6 +8,7 @@ export declare class SqliteSchemaHelper extends SchemaHelper {
|
|
|
8
8
|
private static readonly PARTIAL_WHERE_RE;
|
|
9
9
|
disableForeignKeysSQL(): string;
|
|
10
10
|
enableForeignKeysSQL(): string;
|
|
11
|
+
getForeignKeyCheckSQL(): string;
|
|
11
12
|
supportsSchemaConstraints(): boolean;
|
|
12
13
|
getCreateNamespaceSQL(name: string): string;
|
|
13
14
|
getDropNamespaceSQL(name: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.8-dev.0",
|
|
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",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"kysely": "0.29.8"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@mikro-orm/core": "^7.2.
|
|
53
|
+
"@mikro-orm/core": "^7.2.7"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.
|
|
56
|
+
"@mikro-orm/core": "7.2.8-dev.0"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRaw, LockMode, raw, Utils, } from '@mikro-orm/core';
|
|
1
|
+
import { isRaw, LockMode, raw, SUBQUERY_BRAND, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { QueryType } from './enums.js';
|
|
3
3
|
/** @internal */
|
|
4
4
|
export class NativeQueryBuilder {
|
|
@@ -529,3 +529,9 @@ export class NativeQueryBuilder {
|
|
|
529
529
|
return this.platform.quoteIdentifier(id);
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
|
+
// prototype-level brand recognized by `isSubquery()`, JSON payloads cannot forge it
|
|
533
|
+
Object.defineProperty(NativeQueryBuilder.prototype, SUBQUERY_BRAND, {
|
|
534
|
+
value: true,
|
|
535
|
+
writable: false,
|
|
536
|
+
configurable: false,
|
|
537
|
+
});
|
package/query/QueryBuilder.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var _a;
|
|
2
|
-
import { EntityMetadata, helper, inspect, isRaw, LoadStrategy, LockMode, PopulateHint, QueryFlag, QueryHelper, raw, RawQueryFragment, Reference, ReferenceKind, serialize, Utils, ValidationError, } from '@mikro-orm/core';
|
|
2
|
+
import { EntityMetadata, helper, inspect, isRaw, LoadStrategy, LockMode, PopulateHint, QueryFlag, QueryHelper, raw, RawQueryFragment, Reference, ReferenceKind, serialize, SUBQUERY_BRAND, Utils, ValidationError, } from '@mikro-orm/core';
|
|
3
3
|
import { JoinType, QueryType } from './enums.js';
|
|
4
4
|
import { QueryBuilderHelper } from './QueryBuilderHelper.js';
|
|
5
5
|
import { CriteriaNodeFactory } from './CriteriaNodeFactory.js';
|
|
@@ -2016,7 +2016,7 @@ export class QueryBuilder {
|
|
|
2016
2016
|
this.processNestedJoins();
|
|
2017
2017
|
if (meta && (this.#state.fields?.includes('*') || this.#state.fields?.includes(`${this.mainAlias.aliasName}.*`))) {
|
|
2018
2018
|
const schema = this.getSchema(this.mainAlias);
|
|
2019
|
-
//
|
|
2019
|
+
// Per-column entries are unquoted (meant for `quote`), while `toString()` yields the quoted alias for plain template literals
|
|
2020
2020
|
// For TPT, use helper to resolve correct alias per property (inherited props use parent alias)
|
|
2021
2021
|
const quotedMainAlias = this.platform.quoteIdentifier(this.mainAlias.aliasName).toString();
|
|
2022
2022
|
const columns = meta.createColumnMappingObject(prop => this.helper.getTPTAliasForProperty(prop.name, this.mainAlias.aliasName), quotedMainAlias);
|
|
@@ -2675,3 +2675,5 @@ export class QueryBuilder {
|
|
|
2675
2675
|
}
|
|
2676
2676
|
}
|
|
2677
2677
|
_a = QueryBuilder;
|
|
2678
|
+
// prototype-level brand recognized by `isSubquery()`, JSON payloads cannot forge it
|
|
2679
|
+
Object.defineProperty(QueryBuilder.prototype, SUBQUERY_BRAND, { value: true, writable: false, configurable: false });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALIAS_REPLACEMENT, ALIAS_REPLACEMENT_RE, ArrayType, JsonType, inspect, isRaw, LockMode, OptimisticLockError, QueryOperator, QueryOrderNumeric, raw, Raw, QueryHelper, ReferenceKind, Utils, ValidationError, } from '@mikro-orm/core';
|
|
1
|
+
import { ALIAS_REPLACEMENT, ALIAS_REPLACEMENT_RE, ArrayType, JsonType, inspect, isRaw, isSubquery, LockMode, OptimisticLockError, QueryOperator, QueryOrderNumeric, raw, Raw, QueryHelper, ReferenceKind, Utils, ValidationError, } from '@mikro-orm/core';
|
|
2
2
|
import { EMBEDDABLE_ARRAY_OPS, JoinType, QueryType } from './enums.js';
|
|
3
3
|
/** Captures the column name that follows the alias placeholder. */
|
|
4
4
|
const QUALIFYING_ALIAS_RE = new RegExp(ALIAS_REPLACEMENT_RE + '(?=["\'`\\]]*\\.["\'`\\[]?([\\w$]+))', 'g');
|
|
@@ -613,7 +613,7 @@ export class QueryBuilderHelper {
|
|
|
613
613
|
else {
|
|
614
614
|
const opValue = value[op];
|
|
615
615
|
const opValueIsRaw = isRaw(opValue);
|
|
616
|
-
if (opValueIsRaw ||
|
|
616
|
+
if (opValueIsRaw || isSubquery(opValue)) {
|
|
617
617
|
const query = opValueIsRaw ? opValue : opValue.toRaw();
|
|
618
618
|
const mappedKey = this.mapper(key, type, query, null);
|
|
619
619
|
let sql = this.replaceAliases(query.sql);
|
package/schema/SchemaHelper.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export declare abstract class SchemaHelper {
|
|
|
33
33
|
disableForeignKeysSQL(): string;
|
|
34
34
|
/** Returns SQL to re-enable foreign key checks. */
|
|
35
35
|
enableForeignKeysSQL(): string;
|
|
36
|
+
/** Returns SQL listing rows that violate foreign keys; when non-empty, migrations run with FK checks off and verify afterwards (SQLite). */
|
|
37
|
+
getForeignKeyCheckSQL(): string;
|
|
36
38
|
/** Returns SQL to append to schema migration scripts (e.g., re-enabling FK checks). */
|
|
37
39
|
getSchemaEnd(disableForeignKeys?: boolean): string;
|
|
38
40
|
/** Sets the current schema for the session (e.g. `SET search_path`). */
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -52,6 +52,10 @@ export class SchemaHelper {
|
|
|
52
52
|
enableForeignKeysSQL() {
|
|
53
53
|
return '';
|
|
54
54
|
}
|
|
55
|
+
/** Returns SQL listing rows that violate foreign keys; when non-empty, migrations run with FK checks off and verify afterwards (SQLite). */
|
|
56
|
+
getForeignKeyCheckSQL() {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
55
59
|
/** Returns SQL to append to schema migration scripts (e.g., re-enabling FK checks). */
|
|
56
60
|
getSchemaEnd(disableForeignKeys) {
|
|
57
61
|
if (disableForeignKeys) {
|