Add support for SELECT without FROM

This commit is contained in:
Loic Nageleisen 2017-11-21 11:14:45 +01:00
parent 818da9047a
commit a3712ceefd
2 changed files with 10 additions and 1 deletions

View file

@ -180,7 +180,8 @@ module Rebel::SQL
def select(*fields, from: nil, where: nil, inner: nil, left: nil, right: nil)
raw <<-SQL
SELECT #{names(*fields)} FROM #{name(from)}
SELECT #{names(*fields)}
#{from?(from)}
#{inner?(inner)}
#{left?(left)}
#{right?(right)}
@ -329,6 +330,10 @@ module Rebel::SQL
end.join(' AND ')
end
def from?(from)
from ? "FROM #{name(from)}" : nil
end
def where?(*clause)
clause.any? ? "WHERE #{and_clause(*clause)}" : nil
end