| Class | Insert |
| In: |
lib/insert.rb
|
| Parent: | SqlStatement |
If a block is given: Ignores any parameters given to the method. Executes the block then calls to_sql on the result. Returns an Insert instance with the result of the block‘s execution appended to the SQL statement.
insert = Insert.into[:table1][:column1].values { Select['book'] }
insert.to_sql #=> "insert into table1 (column1) select 'book'"
If no block is given: Returns an Insert instance with the args appended to the SQL statement as values
insert = Insert.into[:table1][:column1, :column2].values(10, 'book') insert.to_sql #=> "insert into table1 (column1, column2) values (10, 'book')"
# File lib/insert.rb, line 48
48: def values(*args)
49: @to_sql += case
50: when block_given? then " #{yield.to_sql}"
51: else " values (#{args.to_sql})"
52: end
53: self
54: end