@mikro-orm/sql
Advanced tools
@@ -9,2 +9,3 @@ import { type RawQueryFragment, type Constructor, type EntityManager, type EntityRepository, type IDatabaseDriver, type IsolationLevel, type MikroORM, Platform } from '@mikro-orm/core'; | ||
| #private; | ||
| private static readonly ORDER_BY_DIRECTIONS; | ||
| protected readonly schemaHelper?: SchemaHelper; | ||
@@ -51,2 +52,8 @@ usesPivotTable(): boolean; | ||
| /** | ||
| * `toLowerCase()` folds every `QueryOrder` enum member (and the normalized `QueryOrderNumeric` | ||
| * values) onto the six allow-listed directions, so only unknown values are rejected. | ||
| * @internal | ||
| */ | ||
| validateOrderByDirection(direction: string): string; | ||
| /** | ||
| * Quotes a collation name for use in COLLATE clauses. | ||
@@ -53,0 +60,0 @@ * @internal |
@@ -8,2 +8,10 @@ import { isRaw, JsonProperty, Platform, raw, Utils, } from '@mikro-orm/core'; | ||
| static #JSON_PROPERTY_NAME_RE = /^[a-zA-Z_][a-zA-Z0-9_]*$/; | ||
| static ORDER_BY_DIRECTIONS = new Set([ | ||
| 'asc', | ||
| 'desc', | ||
| 'asc nulls first', | ||
| 'asc nulls last', | ||
| 'desc nulls first', | ||
| 'desc nulls last', | ||
| ]); | ||
| schemaHelper; | ||
@@ -119,8 +127,21 @@ usesPivotTable() { | ||
| getOrderByExpression(column, direction, collation) { | ||
| const dir = this.validateOrderByDirection(direction); | ||
| if (collation) { | ||
| return [`${column} collate ${this.quoteCollation(collation)} ${direction.toLowerCase()}`]; | ||
| return [`${column} collate ${this.quoteCollation(collation)} ${dir}`]; | ||
| } | ||
| return [`${column} ${direction.toLowerCase()}`]; | ||
| return [`${column} ${dir}`]; | ||
| } | ||
| /** | ||
| * `toLowerCase()` folds every `QueryOrder` enum member (and the normalized `QueryOrderNumeric` | ||
| * values) onto the six allow-listed directions, so only unknown values are rejected. | ||
| * @internal | ||
| */ | ||
| validateOrderByDirection(direction) { | ||
| const dir = ('' + direction).toLowerCase().trim(); | ||
| if (!AbstractSqlPlatform.ORDER_BY_DIRECTIONS.has(dir)) { | ||
| throw new Error(`Invalid order direction: '${direction}'`); | ||
| } | ||
| return dir; | ||
| } | ||
| /** | ||
| * Quotes a collation name for use in COLLATE clauses. | ||
@@ -127,0 +148,0 @@ * @internal |
@@ -117,3 +117,3 @@ import { QueryOrder, DecimalType, DoubleType, } from '@mikro-orm/core'; | ||
| const ret = []; | ||
| const dir = direction.toLowerCase(); | ||
| const dir = this.validateOrderByDirection(direction); | ||
| const col = collation ? `${column} collate ${this.quoteCollation(collation)}` : column; | ||
@@ -120,0 +120,0 @@ if (dir in this.ORDER_BY_NULLS_TRANSLATE) { |
+2
-2
| { | ||
| "name": "@mikro-orm/sql", | ||
| "version": "7.1.7-dev.7", | ||
| "version": "7.1.7-dev.8", | ||
| "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.", | ||
@@ -56,3 +56,3 @@ "keywords": [ | ||
| "peerDependencies": { | ||
| "@mikro-orm/core": "7.1.7-dev.7" | ||
| "@mikro-orm/core": "7.1.7-dev.8" | ||
| }, | ||
@@ -59,0 +59,0 @@ "engines": { |
1056017
0.1%22075
0.13%