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


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

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


2
3
4
# File 'lib/riddle/query/insert.rb', line 2

def columns
  @columns
end

#valuesObject (readonly)

Returns the value of attribute values


2
3
4
# File 'lib/riddle/query/insert.rb', line 2

def values
  @values
end

Instance Method Details

#replace!Object


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

def replace!
  @replace = true
  self
end

#to_sqlObject


16
17
18
# File 'lib/riddle/query/insert.rb', line 16

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