From 223d09a5195e8e77dab3f5d935ec43942b371032 Mon Sep 17 00:00:00 2001 From: TeeAaTeeUu Date: Wed, 12 Aug 2026 09:53:15 +0300 Subject: [PATCH] find matching prepared statement type and value Deduplicate positional parameters, to simplify prepared statements positional parameters in case there are duplicates. For example `${organization_id}` a few times in a more complex nested statement. --- src/types.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/types.js b/src/types.js index 7c7c2b93..c1a64b6a 100644 --- a/src/types.js +++ b/src/types.js @@ -76,21 +76,25 @@ export function handleValue(x, parameters, types, options) { let value = x instanceof Parameter ? x.value : x if (value === undefined) { x instanceof Parameter - ? x.value = options.transform.undefined + ? value = x.value = options.transform.undefined : value = x = options.transform.undefined if (value === undefined) throw Errors.generic('UNDEFINED_VALUE', 'Undefined values are not allowed') } - return '$' + (types.push( + const type = x instanceof Parameter - ? (parameters.push(x.value), x.array - ? x.array[x.type || inferType(x.value)] || x.type || firstIsString(x.value) + ? x.array + ? x.array[x.type || inferType(value)] || x.type || firstIsString(value) : x.type - ) - : (parameters.push(x), inferType(x)) - )) + : inferType(value) + + for (let i = 0; i < parameters.length; i++) + if (parameters[i] === value && types[i] === type) return '$' + (i + 1) + + parameters.push(value) + return '$' + types.push(type) } const defaultHandlers = typeHandlers(types)