4.21.0.txt

doc/release_notes/4.21.0.txt
Last Update: 2015-04-01 08:28:35 -0700

New Features

  • SQL::GenericExpression#=~ has been added as an alternative method of specifying equality/inclusion/identity. Previously, you had to use a hash. This led to some slightly weird looking syntax when used inside virtual rows:

    DB[:items].where{{function(:column)=>0}}
    # SELECT FROM items WHERE function(column) = 0

    You can now use =~ as an equivalent:

    DB[:items].where{function(:column) =~ 0}
    # SELECT FROM items WHERE function(column) = 0

    Like when using a hash, this works also for inclusion:

    DB[:items].where{function(:column) =~ [1,2,3]}
    # SELECT FROM items WHERE function(column) IN (1, 2, 3)

    for identity:

    DB[:items].where{function(:column) =~ nil}
    # SELECT FROM items WHERE function(column) IS NULL

    and for matching (on MySQL/PostgreSQL):

    DB[:items].where{function(:column) =~ /foo/i}
    # SELECT FROM items WHERE function(column) ~* 'foo'

    This new syntax makes more complex conditions simpler to express:

    DB[:items].where{(function(:column) =~ 0) | (column =~ 1)}
    # SELECT FROM items WHERE function(column) = 0 OR column = 1

    compared to previous versions of Sequel:

    DB[:items].where{Sequel.|({function(:column) => 0}, {:column => 1})}

    On ruby 1.9+, you can also use SQL::GenericExpression#!~ to invert the condition:

    DB[:items].where{function(:column) !~ 0}
    # SELECT FROM items WHERE function(column) != 0
    
    DB[:items].where{function(:column) !~ [1,2,3]}
    # SELECT FROM items WHERE function(column) NOT IN (1, 2, 3)
    
    DB[:items].where{function(:column) !~ nil}
    # SELECT FROM items WHERE function(column) IS NOT NULL
    
    DB[:items].where{function(:column) !~ /foo/i}
    # SELECT FROM items WHERE function(column) !~* 'foo'

    This makes it simpler to write inverted conditions. Ruby 1.8 doesn't support overriding the !~ method, but you can still use the unary ~ method to invert:

    DB[:items].where{~(function(:column) =~ 0)}
  • Database#add_named_conversion_proc has been added on PostgreSQL to make it easier to add conversion procs by name instead of by OID:

    DB.add_named_conversion_proc(:citext){|s| s}
  • Database#full_text_search on PostgreSQL now supports :tsquery and :tsvector options for using existing tsquery and/or tsvector arguments, instead of assuming the arguments are query terms or the text to be search.

Other Improvements

  • Database#transaction now works inside after_commit and after_rollback hooks. Previously, it didn't work correctly as it thought it was already inside the previously committed/rolled back transaction.

  • Sequel.pg_jsonb now returns JSONBOp instances instead of JSONOp instances when passed other than Array or Hash.

  • The tinytds adapter no longer tries to cancel a query on a closed connection, which was causing an exception to be raised.

Backwards Compatibility

  • The default root name used in the JSON serializer is now demodulized before being underscored. This changes the behavior when the model is namespaced. For example, if the model class name is Mod::Model, the previous default root name would be “mod/model”, the new default root name is “model”.

  • If you were calling =~ or !~ on SQL::GenericExpression objects and expecting the default ruby behavior of returning nil for =~ and true for !~, you'll have to update your code.