Sha256: 3e7813ee57671b16f8aaf2f2237223c0bca6e7829e316c56d449d24c54d1fad5
Contents?: true
Size: 1.07 KB
Versions: 6
Compression:
Stored size: 1.07 KB
Contents
# This changes Sequel's literalization of IN/NOT IN with an empty # array value to consider NULL values if one of the referenced # columns is NULL: # # DB[:test].where(:name=>[]) # # SELECT * FROM test WHERE (name != name) # DB[:test].exclude(:name=>[]) # # SELECT * FROM test WHERE (name = name) # # The default Sequel behavior is to ignore NULLs, as the above # query is not generally optimized well by databases. # # You can load this extension into specific datasets: # # ds = DB[:table] # ds = ds.extension(:empty_array_consider_nulls) # # Or you can load it into all of a database's datasets, which # is probably the desired behavior if you are using this extension: # # DB.extension(:empty_array_consider_nulls) # module Sequel module EmptyArrayConsiderNulls # Use a simple expression that is always true or false, never NULL. def empty_array_value(op, cols) c = Array(cols) SQL::BooleanExpression.from_value_pairs(c.zip(c), :AND, op == :IN) end end Dataset.register_extension(:empty_array_consider_nulls, EmptyArrayConsiderNulls) end
Version data entries
6 entries across 6 versions & 1 rubygems