Class: Baza::SqlQueries::NonAtomicUpsert
- Inherits:
-
Object
- Object
- Baza::SqlQueries::NonAtomicUpsert
- Defined in:
- lib/baza/sql_queries/non_atomic_upsert.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args) ⇒ NonAtomicUpsert
constructor
A new instance of NonAtomicUpsert.
Constructor Details
#initialize(args) ⇒ NonAtomicUpsert
Returns a new instance of NonAtomicUpsert.
2 3 4 5 6 7 8 |
# File 'lib/baza/sql_queries/non_atomic_upsert.rb', line 2 def initialize(args) @db = args.fetch(:db) @table_name = args.fetch(:table_name) @updates = args.fetch(:updates) @terms = args.fetch(:terms) @buffer = args[:buffer] end |
Instance Method Details
#execute ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/baza/sql_queries/non_atomic_upsert.rb', line 10 def execute row = @db.single(@table_name, @terms) if @buffer obj = @buffer else obj = @db end if row obj.update(@table_name, @updates, @terms) else obj.insert(@table_name, @terms.merge(@updates)) end end |