Class: PGB::Query

Inherits:
Expression show all
Extended by:
Mutable
Includes:
Executable
Defined in:
lib/pgb/query.rb

Instance Method Summary collapse

Methods included from Mutable

mutable

Methods included from Executable

#each

Methods included from SQLDisplayable

#inspect, #to_s

Constructor Details

#initialize(table = nil, *expressions) ⇒ Query

TODO Support everything www.postgresql.org/docs/current/sql-select.html TODO Table can be other things, e.g. query



11
12
13
14
# File 'lib/pgb/query.rb', line 11

def initialize(table = nil, *expressions)
  self.table = table
  self.expressions = expressions
end

Instance Method Details

#to_sqlObject

TODO Can not select star if no table



17
18
19
20
21
# File 'lib/pgb/query.rb', line 17

def to_sql
  "SELECT #{expressions.any? ? expressions.map(&:to_sql).join(', ') : '*'}".then do
    table ? "#{_1} FROM #{table}" : _1
  end
end