Class: Sqlbuilder::Statements::Insert
Instance Method Summary
collapse
#build_columns, #build_into, #build_values
Constructor Details
#initialize(utils) ⇒ Insert
Returns a new instance of Insert.
8
9
10
11
12
13
|
# File 'lib/sqlbuilder/statements/insert.rb', line 8
def initialize(utils)
@utils = utils
@columns = []
@values_list = []
@records = []
end
|
Instance Method Details
#build ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/sqlbuilder/statements/insert.rb', line 39
def build
sql = "INSERT"
unless @records.empty?
@columns = @records.first.keys
@records.each {|record| @values_list << record.values }
end
sql << " #{build_into}"
sql << " #{build_columns}"
sql << " #{build_values}"
sql
end
|
#columns(columns) ⇒ Object
21
22
23
24
25
|
# File 'lib/sqlbuilder/statements/insert.rb', line 21
def columns(columns)
@columns = columns
self
end
|
#into(table) ⇒ Object
15
16
17
18
19
|
# File 'lib/sqlbuilder/statements/insert.rb', line 15
def into(table)
@table = table
self
end
|
#record(key_value_hash) ⇒ Object
33
34
35
36
37
|
# File 'lib/sqlbuilder/statements/insert.rb', line 33
def record(key_value_hash)
@records << key_value_hash
self
end
|
#values(single_row_values) ⇒ Object
27
28
29
30
31
|
# File 'lib/sqlbuilder/statements/insert.rb', line 27
def values(single_row_values)
@values_list << single_row_values
self
end
|