Class: Baza::SqlQueries::GenericInsert
- Inherits:
-
Object
- Object
- Baza::SqlQueries::GenericInsert
- Defined in:
- lib/baza/sql_queries/generic_insert.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args) ⇒ GenericInsert
constructor
A new instance of GenericInsert.
- #to_sql ⇒ Object
Constructor Details
#initialize(args) ⇒ GenericInsert
Returns a new instance of GenericInsert.
2 3 4 5 6 7 8 9 10 |
# File 'lib/baza/sql_queries/generic_insert.rb', line 2 def initialize(args) @db = args.fetch(:db) @table_name = args.fetch(:table_name) @data = args.fetch(:data) @buffer = args[:buffer] @return_sql = args[:return_sql] @return_id = args[:return_id] @replace_line_breaks = args[:replace_line_breaks] end |
Instance Method Details
#execute ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/baza/sql_queries/generic_insert.rb', line 12 def execute if @return_sql to_sql elsif @buffer @buffer.query(to_sql) else @db.query(to_sql) @db.last_id if @return_id end end |
#to_sql ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/baza/sql_queries/generic_insert.rb', line 23 def to_sql sql = "INSERT INTO #{@db.quote_table(@table_name)}" if !@data || @data.empty? sql << " #{sql_default_values}" else sql << " #{sql_columns} VALUES #{sql_values}" end sql end |