@mikro-orm/knex
Advanced tools
@@ -35,2 +35,8 @@ import { Platform, type Constructor, type EntityManager, type EntityRepository, type IDatabaseDriver, type MikroORM, type IsolationLevel } from '@mikro-orm/core'; | ||
| getOrderByExpression(column: string, direction: string): string[]; | ||
| /** | ||
| * `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; | ||
| } |
@@ -8,2 +8,10 @@ "use strict"; | ||
| const schema_1 = require("./schema"); | ||
| const ORDER_BY_DIRECTIONS = new Set([ | ||
| 'asc', | ||
| 'desc', | ||
| 'asc nulls first', | ||
| 'asc nulls last', | ||
| 'desc nulls first', | ||
| 'desc nulls last', | ||
| ]); | ||
| class AbstractSqlPlatform extends core_1.Platform { | ||
@@ -109,5 +117,17 @@ schemaHelper; | ||
| getOrderByExpression(column, direction) { | ||
| return [`${column} ${direction.toLowerCase()}`]; | ||
| return [`${column} ${this.validateOrderByDirection(direction)}`]; | ||
| } | ||
| /** | ||
| * `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 (!ORDER_BY_DIRECTIONS.has(dir)) { | ||
| throw new Error(`Invalid order direction: '${direction}'`); | ||
| } | ||
| return dir; | ||
| } | ||
| } | ||
| exports.AbstractSqlPlatform = AbstractSqlPlatform; |
@@ -105,3 +105,3 @@ "use strict"; | ||
| const ret = []; | ||
| const dir = direction.toLowerCase(); | ||
| const dir = this.validateOrderByDirection(direction); | ||
| if (dir in this.ORDER_BY_NULLS_TRANSLATE) { | ||
@@ -108,0 +108,0 @@ ret.push(`${column} ${this.ORDER_BY_NULLS_TRANSLATE[dir]}`); |
+2
-2
| { | ||
| "name": "@mikro-orm/knex", | ||
| "version": "6.6.16-dev.0", | ||
| "version": "6.6.16-dev.1", | ||
| "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.", | ||
@@ -69,3 +69,3 @@ "main": "index.js", | ||
| "peerDependencies": { | ||
| "@mikro-orm/core": "6.6.16-dev.0", | ||
| "@mikro-orm/core": "6.6.16-dev.1", | ||
| "better-sqlite3": "*", | ||
@@ -72,0 +72,0 @@ "libsql": "*", |
555608
0.17%11295
0.23%