Class: InsertInto::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/insert_into/statement.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name) ⇒ Statement

Returns a new instance of Statement.



5
6
7
8
# File 'lib/insert_into/statement.rb', line 5

def initialize(table_name)
  @table_name = table_name
  @rows = []
end

Instance Attribute Details

#table_nameObject (readonly)

Returns the value of attribute table_name.



3
4
5
# File 'lib/insert_into/statement.rb', line 3

def table_name
  @table_name
end

Instance Method Details

#new_row {|row| ... } ⇒ Object

Yields:

  • (row)


10
11
12
13
14
# File 'lib/insert_into/statement.rb', line 10

def new_row
  row = Row.new
  yield row
  @rows << row
end

#to_sqlObject



16
17
18
# File 'lib/insert_into/statement.rb', line 16

def to_sql
  "INSERT INTO #{table_name} (#{column_names.join(',')}) VALUES #{values_string};"
end