module Sequel::Postgres::AutoParameterizeInArray

  1. lib/sequel/extensions/pg_auto_parameterize_in_array.rb

Enable automatically parameterizing queries.

Methods

Public Instance

  1. complex_expression_sql_append

Public Instance methods

complex_expression_sql_append(sql, op, args)

Transform column IN (…) expressions into column = ANY($) and column NOT IN (…) expressions into column != ALL($) using an array bound variable for the ANY/ALL argument, if all values inside the predicate are of the same type and the type is handled by the extension. This is the same optimization PostgreSQL performs internally, but this reduces the number of bound variables.

[show source]
    # File lib/sequel/extensions/pg_auto_parameterize_in_array.rb
 99 def complex_expression_sql_append(sql, op, args)
100   case op
101   when :IN, :"NOT IN"
102     l, r = args
103     if auto_param?(sql) && (type = _bound_variable_type_for_array(r))
104       if op == :IN 
105         op = :"="
106         func = :ANY
107       else
108         op = :!=
109         func = :ALL
110       end
111       args = [l, Sequel.function(func, _convert_array_to_pg_array_with_type(r, type))]
112     end
113   end
114 
115   super
116 end