@mikro-orm/sql 7.1.7-dev.7 → 7.1.7-dev.8
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/AbstractSqlPlatform.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
|
6
6
|
/** Base class for SQL database platforms, providing SQL generation and quoting utilities. */
|
|
7
7
|
export declare abstract class AbstractSqlPlatform extends Platform {
|
|
8
8
|
#private;
|
|
9
|
+
private static readonly ORDER_BY_DIRECTIONS;
|
|
9
10
|
protected readonly schemaHelper?: SchemaHelper;
|
|
10
11
|
usesPivotTable(): boolean;
|
|
11
12
|
indexForeignKeys(): boolean;
|
|
@@ -46,6 +47,12 @@ export declare abstract class AbstractSqlPlatform extends Platform {
|
|
|
46
47
|
* @internal
|
|
47
48
|
*/
|
|
48
49
|
getOrderByExpression(column: string, direction: string, collation?: string): string[];
|
|
50
|
+
/**
|
|
51
|
+
* `toLowerCase()` folds every `QueryOrder` enum member (and the normalized `QueryOrderNumeric`
|
|
52
|
+
* values) onto the six allow-listed directions, so only unknown values are rejected.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
validateOrderByDirection(direction: string): string;
|
|
49
56
|
/**
|
|
50
57
|
* Quotes a collation name for use in COLLATE clauses.
|
|
51
58
|
* @internal
|
package/AbstractSqlPlatform.js
CHANGED
|
@@ -5,6 +5,14 @@ import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
|
5
5
|
/** Base class for SQL database platforms, providing SQL generation and quoting utilities. */
|
|
6
6
|
export class AbstractSqlPlatform extends Platform {
|
|
7
7
|
static #JSON_PROPERTY_NAME_RE = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
8
|
+
static ORDER_BY_DIRECTIONS = new Set([
|
|
9
|
+
'asc',
|
|
10
|
+
'desc',
|
|
11
|
+
'asc nulls first',
|
|
12
|
+
'asc nulls last',
|
|
13
|
+
'desc nulls first',
|
|
14
|
+
'desc nulls last',
|
|
15
|
+
]);
|
|
8
16
|
schemaHelper;
|
|
9
17
|
usesPivotTable() {
|
|
10
18
|
return true;
|
|
@@ -115,10 +123,23 @@ export class AbstractSqlPlatform extends Platform {
|
|
|
115
123
|
* @internal
|
|
116
124
|
*/
|
|
117
125
|
getOrderByExpression(column, direction, collation) {
|
|
126
|
+
const dir = this.validateOrderByDirection(direction);
|
|
118
127
|
if (collation) {
|
|
119
|
-
return [`${column} collate ${this.quoteCollation(collation)} ${
|
|
128
|
+
return [`${column} collate ${this.quoteCollation(collation)} ${dir}`];
|
|
120
129
|
}
|
|
121
|
-
return [`${column} ${
|
|
130
|
+
return [`${column} ${dir}`];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* `toLowerCase()` folds every `QueryOrder` enum member (and the normalized `QueryOrderNumeric`
|
|
134
|
+
* values) onto the six allow-listed directions, so only unknown values are rejected.
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
validateOrderByDirection(direction) {
|
|
138
|
+
const dir = ('' + direction).toLowerCase().trim();
|
|
139
|
+
if (!AbstractSqlPlatform.ORDER_BY_DIRECTIONS.has(dir)) {
|
|
140
|
+
throw new Error(`Invalid order direction: '${direction}'`);
|
|
141
|
+
}
|
|
142
|
+
return dir;
|
|
122
143
|
}
|
|
123
144
|
/**
|
|
124
145
|
* Quotes a collation name for use in COLLATE clauses.
|
|
@@ -114,7 +114,7 @@ export class BaseMySqlPlatform extends AbstractSqlPlatform {
|
|
|
114
114
|
}
|
|
115
115
|
getOrderByExpression(column, direction, collation) {
|
|
116
116
|
const ret = [];
|
|
117
|
-
const dir =
|
|
117
|
+
const dir = this.validateOrderByDirection(direction);
|
|
118
118
|
const col = collation ? `${column} collate ${this.quoteCollation(collation)}` : column;
|
|
119
119
|
if (dir in this.ORDER_BY_NULLS_TRANSLATE) {
|
|
120
120
|
ret.push(`${col} ${this.ORDER_BY_NULLS_TRANSLATE[dir]}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.7-dev.
|
|
3
|
+
"version": "7.1.7-dev.8",
|
|
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": "^7.1.6"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.7-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.7-dev.8"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|