@mikro-orm/sql
Advanced tools
+2
-2
| { | ||
| "name": "@mikro-orm/sql", | ||
| "version": "7.1.13-dev.15", | ||
| "version": "7.1.13-dev.16", | ||
| "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.13-dev.15" | ||
| "@mikro-orm/core": "7.1.13-dev.16" | ||
| }, | ||
@@ -59,0 +59,0 @@ "engines": { |
| import { type EntityMetadata, type EntityProperty, type Type } from '@mikro-orm/core'; | ||
| import { type CommonTableExpressionNameNode, type DeleteQueryNode, type InsertQueryNode, type JoinNode, type MergeQueryNode, type OperationNode, type QueryId, type SelectQueryNode, type UpdateQueryNode, type WithNode, ColumnNode, IdentifierNode, OperationNodeTransformer, SelectionNode, TableNode, ValueNode } from 'kysely'; | ||
| import { type BinaryOperationNode, type CommonTableExpressionNameNode, type DeleteQueryNode, type InsertQueryNode, type JoinNode, type MergeQueryNode, type OperationNode, type QueryId, type SelectQueryNode, type UpdateQueryNode, type WithNode, ColumnNode, IdentifierNode, OperationNodeTransformer, SelectionNode, TableNode, ValueNode } from 'kysely'; | ||
| import type { MikroKyselyPluginOptions } from './index.js'; | ||
@@ -31,2 +31,8 @@ import type { SqlEntityManager } from '../SqlEntityManager.js'; | ||
| processUpdateValues(node: UpdateQueryNode, meta: EntityMetadata): UpdateQueryNode; | ||
| transformBinaryOperation(node: BinaryOperationNode, queryId: QueryId): BinaryOperationNode; | ||
| /** Resolve the entity property a comparison's left operand refers to, so its value operand can be converted. */ | ||
| resolveOperandProperty(operand: OperationNode): { | ||
| prop: EntityProperty; | ||
| fieldName: string; | ||
| } | undefined; | ||
| processInputValueNode(prop: EntityProperty | undefined, fieldName: string | undefined, valueNode: ValueNode): OperationNode; | ||
@@ -33,0 +39,0 @@ expandSelections(selections: readonly SelectionNode[]): readonly SelectionNode[]; |
@@ -458,2 +458,56 @@ import { ReferenceKind, isRaw, } from '@mikro-orm/core'; | ||
| } | ||
| transformBinaryOperation(node, queryId) { | ||
| const transformed = super.transformBinaryOperation(node, queryId); | ||
| if (!this.#options.convertValues) { | ||
| return transformed; | ||
| } | ||
| const resolved = this.resolveOperandProperty(transformed.leftOperand); | ||
| if (!resolved) { | ||
| return transformed; | ||
| } | ||
| const { prop, fieldName } = resolved; | ||
| const right = transformed.rightOperand; | ||
| if (ValueNode.is(right)) { | ||
| const converted = this.processInputValueNode(prop, fieldName, right); | ||
| return converted === right ? transformed : { ...transformed, rightOperand: converted }; | ||
| } | ||
| if (PrimitiveValueListNode.is(right)) { | ||
| // upgrade to ValueListNode when the type needs SQL-side wrapping, since | ||
| // PrimitiveValueListNode can only hold primitives | ||
| if (prop.hasConvertToDatabaseValueSQL) { | ||
| const values = right.values.map(value => this.processInputValueNode(prop, fieldName, ValueNode.create(value))); | ||
| return { ...transformed, rightOperand: ValueListNode.create(values) }; | ||
| } | ||
| const values = right.values.map(value => this.prepareInputValue(prop, value, true)); | ||
| return values.every((value, idx) => value === right.values[idx]) | ||
| ? transformed | ||
| : { ...transformed, rightOperand: PrimitiveValueListNode.create(values) }; | ||
| } | ||
| if (ValueListNode.is(right)) { | ||
| let changed = false; | ||
| const values = right.values.map(valueNode => { | ||
| if (!ValueNode.is(valueNode)) { | ||
| return valueNode; | ||
| } | ||
| const converted = this.processInputValueNode(prop, fieldName, valueNode); | ||
| if (converted !== valueNode) { | ||
| changed = true; | ||
| } | ||
| return converted; | ||
| }); | ||
| return changed ? { ...transformed, rightOperand: ValueListNode.create(values) } : transformed; | ||
| } | ||
| return transformed; | ||
| } | ||
| /** Resolve the entity property a comparison's left operand refers to, so its value operand can be converted. */ | ||
| resolveOperandProperty(operand) { | ||
| if (!ReferenceNode.is(operand) || !ColumnNode.is(operand.column)) { | ||
| return undefined; | ||
| } | ||
| const tableName = operand.table ? this.getTableName(operand.table) : undefined; | ||
| const meta = this.findOwnerMeta(tableName); | ||
| const fieldName = this.normalizeColumnName(operand.column.column); | ||
| const prop = this.findProperty(meta, fieldName); | ||
| return prop ? { prop, fieldName } : undefined; | ||
| } | ||
| processInputValueNode(prop, fieldName, valueNode) { | ||
@@ -547,4 +601,9 @@ const converted = this.prepareInputValue(prop, valueNode.value, true); | ||
| } | ||
| // the stack can be empty when transforming a raw root node with embedded expressions | ||
| const context = this.#contextStack[this.#contextStack.length - 1]; | ||
| if (!context) { | ||
| return undefined; | ||
| } | ||
| let single; | ||
| for (const meta of this.#contextStack[this.#contextStack.length - 1].values()) { | ||
| for (const meta of context.values()) { | ||
| if (!meta) { | ||
@@ -551,0 +610,0 @@ continue; |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
1084371
0.3%22572
0.29%