Sha256: 4412ffb4818ce7e3be43f05a89793f950524304663ebd77c772d326721f1c437

Contents?: true

Size: 1002 Bytes

Versions: 12

Compression:

Stored size: 1002 Bytes

Contents

# This changes Sequel's literalization of IN/NOT IN with an empty
# array value to not return NULL even if one of the referenced
# columns is NULL:
#
#   DB[:test].where(:name=>[])
#   # SELECT * FROM test WHERE (1 = 0)
#   DB[:test].exclude(:name=>[])
#   # SELECT * FROM test WHERE (1 = 1)
#
# The default Sequel behavior is to respect NULLs, so that when
# name is NULL, the expression returns NULL.
#
# You can load this extension into specific datasets:
#
#   ds = DB[:table]
#   ds = ds.extension(:empty_array_ignore_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_ignore_nulls)

#
module Sequel
  module EmptyArrayIgnoreNulls
    # Use a simple expression that is always true or false, never NULL.
    def empty_array_value(op, cols)
      {1 => ((op == :IN) ? 0 : 1)}
    end
    
  end

  Dataset.register_extension(:empty_array_ignore_nulls, EmptyArrayIgnoreNulls)
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
sequel-4.24.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.23.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.22.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.21.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.20.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.19.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.18.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.17.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.16.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/sequel-4.15.0/lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.15.0 lib/sequel/extensions/empty_array_ignore_nulls.rb
sequel-4.14.0 lib/sequel/extensions/empty_array_ignore_nulls.rb