Skip to content

Commit cafe88e

Browse files
pimpinclaude
andcommitted
Pass arrays as single positional parameter for prepared-statement caching
Instead of expanding arrays into individual parameters (e.g. IN [$1, $2]), pass the whole array as one parameter (e.g. IN $1). This keeps the query string stable regardless of array length, enabling Couchbase to cache the prepared statement for IN queries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c2cffd3 commit cafe88e

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib/couchbase-orm/utilities/query_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module QueryHelper
55
module ClassMethods
66

77
def serialize_for_binding(value)
8-
if [DateTime, Time].any? { |clazz| value.is_a?(clazz) }
8+
if value.is_a?(Array)
9+
value.map { |v| serialize_for_binding(v) }
10+
elsif [DateTime, Time].any? { |clazz| value.is_a?(clazz) }
911
value.iso8601(@precision || 0)
1012
elsif value.is_a?(Date)
1113
value.to_s
@@ -15,9 +17,7 @@ def serialize_for_binding(value)
1517
end
1618

1719
def bind(value, params)
18-
if value.is_a?(Array)
19-
"[#{value.map { |v| bind(v, params) }.join(', ')}]"
20-
elsif value.nil?
20+
if value.nil?
2121
nil
2222
else
2323
params << serialize_for_binding(value)

0 commit comments

Comments
 (0)