mirror of
https://github.com/lloeki/rebel.git
synced 2025-12-06 10:04:39 +01:00
wrap AND first member w/ parens
This commit is contained in:
parent
ee34b9c600
commit
075957be04
2 changed files with 15 additions and 3 deletions
|
|
@ -65,6 +65,10 @@ module Rebel::SQL
|
|||
Raw.new("(#{self})")
|
||||
end
|
||||
|
||||
def parens?
|
||||
wants_parens? ? parens : self
|
||||
end
|
||||
|
||||
def as(n)
|
||||
Raw.new(self + " AS #{Rebel::SQL.name(n)}")
|
||||
end
|
||||
|
|
@ -82,7 +86,7 @@ module Rebel::SQL
|
|||
end
|
||||
|
||||
def and(*clause)
|
||||
Raw.new("#{self} AND #{Rebel::SQL.and_clause(*clause)}")
|
||||
Raw.new("#{self.parens?} AND #{Rebel::SQL.and_clause(*clause)}")
|
||||
end
|
||||
|
||||
def or(*clause)
|
||||
|
|
@ -313,7 +317,7 @@ module Rebel::SQL
|
|||
case e
|
||||
when Hash then and_clause(*e.to_a)
|
||||
when Array then clause_term(e[0], e[1])
|
||||
when Raw then e.wants_parens? && clause.count > 1 ? "(#{e})" : e
|
||||
when Raw then e.parens?
|
||||
when String then e
|
||||
else raise NotImplementedError, e.class
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue