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.



76
77
78
79
# File 'lib/card/query.rb', line 76

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

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



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

def conditions
  @conditions
end

#distinctObject

Returns the value of attribute distinct.



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

def distinct
  @distinct
end

#fieldsObject

Returns the value of attribute fields.



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

def fields
  @fields
end

#groupObject

Returns the value of attribute group.



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

def group
  @group
end

#joinsObject

Returns the value of attribute joins.



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

def joins
  @joins
end

#limitObject

Returns the value of attribute limit.



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

def limit
  @limit
end

#offsetObject

Returns the value of attribute offset.



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

def offset
  @offset
end

#orderObject

Returns the value of attribute order.



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

def order
  @order
end

#tablesObject

Returns the value of attribute tables.



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

def tables
  @tables
end

Instance Method Details

#to_sObject



81
82
83
84
85
86
# File 'lib/card/query.rb', line 81

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