Support ESCAPE clause #166

Closed
wants to merge 1 commit into
from

3 participants

@labocho

Added Arel::Nodes::Escape to escape special characters (% or _) in LIKE pattern.

# Usage
table = Arel::Table.new(:drinks)
query = table.project relation[:id]

escaped_pattern = Arel::Nodes::Escape.new('%100!% fruit juice', '!')
query.where relation[:name].matches(escaped_pattern)
query.to_sql
# => SELECT "drinks"."id" FROM "drinks" WHERE "drinks"."name" LIKE '%100!% fruit juice' ESCAPE '!'
@avit

I like this. Should we also allow an optional argument for matches and matches_any, so it can be chained correctly:

relation[:name].matches('%100!% fruit juice', '!')
relation[:name].matches_any(['%100!% fruit juice', '%10!% sales tax'], '!')
@matthewd
Ruby on Rails member

IMHO, this is more like a third attribute of a Matches, rather than a distinct node in its own right

@matthewd matthewd closed this in #318 Sep 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment