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.



66
67
68
69
# File 'lib/card/query.rb', line 66

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

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



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

def conditions
  @conditions
end

#distinctObject

Returns the value of attribute distinct.



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

def distinct
  @distinct
end

#fieldsObject

Returns the value of attribute fields.



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

def fields
  @fields
end

#groupObject

Returns the value of attribute group.



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

def group
  @group
end

#joinsObject

Returns the value of attribute joins.



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

def joins
  @joins
end

#limitObject

Returns the value of attribute limit.



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

def limit
  @limit
end

#offsetObject

Returns the value of attribute offset.



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

def offset
  @offset
end

#orderObject

Returns the value of attribute order.



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

def order
  @order
end

#tablesObject

Returns the value of attribute tables.



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

def tables
  @tables
end

Instance Method Details

#to_sObject



71
72
73
74
75
76
# File 'lib/card/query.rb', line 71

def to_s
  select = fields.reject(&:blank?) * ', '
  where = conditions.reject(&:blank?) * ' and '
  
  ['(SELECT', distinct, select, 'FROM', tables, joins, 'WHERE', where, group, order, limit, offset, ')'].compact * ' '
end