escaped_like.rb

lib/sequel/extensions/escaped_like.rb
Last Update: 2018-05-25 14:49:16 -0700

The escaped_like extension adds escaped_like and escaped_ilike methods to Sequel::SQL::StringMethods, which allow them to be easily used with most of Sequel’s expression objects. Example:

DB[:table].where{string_column.escaped_like('?%', user_input)}
# user_input is 'foo':
#  SELECT * FROM table WHERE string_column LIKE 'foo%' ESCAPE '\'
# user_input is '%foo':
#  SELECT * FROM table WHERE string_column LIKE '\%foo%' ESCAPE '\'

To load the extension:

Sequel.extension :escaped_like

Related modules: Sequel::SQL::StringMethods, Sequel::SQL::EscapedLikeExpression