2010-09-23 14:45:29 -04:00
|
|
|
module Arel
|
|
|
|
module Visitors
|
|
|
|
class PostgreSQL < Arel::Visitors::ToSql
|
2010-09-23 16:07:48 -04:00
|
|
|
private
|
2010-10-13 16:23:52 -04:00
|
|
|
|
2014-04-08 20:16:21 -04:00
|
|
|
def visit_Arel_Nodes_Matches o, collector
|
2015-12-05 18:54:09 -05:00
|
|
|
op = o.case_sensitive ? ' LIKE ' : ' ILIKE '
|
|
|
|
collector = infix_value o, collector, op
|
2014-12-24 22:58:42 -05:00
|
|
|
if o.escape
|
|
|
|
collector << ' ESCAPE '
|
|
|
|
visit o.escape, collector
|
|
|
|
else
|
|
|
|
collector
|
|
|
|
end
|
2010-09-29 15:50:24 -04:00
|
|
|
end
|
|
|
|
|
2014-04-08 20:16:21 -04:00
|
|
|
def visit_Arel_Nodes_DoesNotMatch o, collector
|
2015-12-05 18:54:09 -05:00
|
|
|
op = o.case_sensitive ? ' NOT LIKE ' : ' NOT ILIKE '
|
|
|
|
collector = infix_value o, collector, op
|
2014-12-24 22:58:42 -05:00
|
|
|
if o.escape
|
|
|
|
collector << ' ESCAPE '
|
|
|
|
visit o.escape, collector
|
|
|
|
else
|
|
|
|
collector
|
|
|
|
end
|
2010-09-29 15:50:24 -04:00
|
|
|
end
|
|
|
|
|
2014-04-08 20:16:21 -04:00
|
|
|
def visit_Arel_Nodes_Regexp o, collector
|
|
|
|
infix_value o, collector, ' ~ '
|
2014-03-07 08:15:33 -05:00
|
|
|
end
|
|
|
|
|
2014-04-08 20:16:21 -04:00
|
|
|
def visit_Arel_Nodes_NotRegexp o, collector
|
|
|
|
infix_value o, collector, ' !~ '
|
2014-03-07 08:15:33 -05:00
|
|
|
end
|
|
|
|
|
2014-04-08 20:16:21 -04:00
|
|
|
def visit_Arel_Nodes_DistinctOn o, collector
|
|
|
|
collector << "DISTINCT ON ( "
|
|
|
|
visit(o.expr, collector) << " )"
|
2010-09-23 16:07:48 -04:00
|
|
|
end
|
2014-11-17 17:52:38 -05:00
|
|
|
|
|
|
|
def visit_Arel_Nodes_BindParam o, collector
|
|
|
|
collector.add_bind(o) { |i| "$#{i}" }
|
|
|
|
end
|
2010-09-23 14:45:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|