Class: Card::Query::SqlStatement

Inherits:
Object
  • Object
show all
Defined in:
lib/card/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSqlStatement

Returns a new instance of SqlStatement.



63
64
65
66
# File 'lib/card/query.rb', line 63

def initialize
  @fields, @joins, @conditions = [],[],[],[]
  @tables, @group, @order, @limit, @offset = "","","","",""
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



61
62
63
# File 'lib/card/query.rb', line 61

def conditions
  @conditions
end

#fieldsObject

Returns the value of attribute fields.



61
62
63
# File 'lib/card/query.rb', line 61

def fields
  @fields
end

#groupObject

Returns the value of attribute group.



61
62
63
# File 'lib/card/query.rb', line 61

def group
  @group
end

#joinsObject

Returns the value of attribute joins.



61
62
63
# File 'lib/card/query.rb', line 61

def joins
  @joins
end

#limitObject

Returns the value of attribute limit.



61
62
63
# File 'lib/card/query.rb', line 61

def limit
  @limit
end

#offsetObject

Returns the value of attribute offset.



61
62
63
# File 'lib/card/query.rb', line 61

def offset
  @offset
end

#orderObject

Returns the value of attribute order.



61
62
63
# File 'lib/card/query.rb', line 61

def order
  @order
end

#tablesObject

Returns the value of attribute tables.



61
62
63
# File 'lib/card/query.rb', line 61

def tables
  @tables
end

Instance Method Details

#to_sObject



68
69
70
71
72
73
# File 'lib/card/query.rb', line 68

def to_s
  "(
select #{fields.reject(&:blank?).join(', ')} from #{tables} #{joins.join(' ')}
where #{conditions.reject(&:blank?).join(' and ')} #{group} #{order} #{limit} #{offset}
)"
end