Class: Riddle::Query::Insert

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, columns = [], values = []) ⇒ Insert

Returns a new instance of Insert.


6
7
8
9
10
11
# File 'lib/riddle/query/insert.rb', line 6

def initialize(index, columns = [], values = [])
  @index   = index
  @columns = columns
  @values  = values.first.is_a?(Array) ? values : [values]
  @replace = false
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns


4
5
6
# File 'lib/riddle/query/insert.rb', line 4

def columns
  @columns
end

#valuesObject (readonly)

Returns the value of attribute values


4
5
6
# File 'lib/riddle/query/insert.rb', line 4

def values
  @values
end

Instance Method Details

#replace!Object


13
14
15
16
# File 'lib/riddle/query/insert.rb', line 13

def replace!
  @replace = true
  self
end

#to_sqlObject


18
19
20
# File 'lib/riddle/query/insert.rb', line 18

def to_sql
  "#{command} INTO #{@index} (#{columns_to_s}) VALUES (#{values_to_s})"
end