Class: River::Driver::Sequel
- Inherits:
-
Object
- Object
- River::Driver::Sequel
- Defined in:
- lib/driver.rb
Overview
Instance Method Summary collapse
-
#initialize(db) ⇒ Sequel
constructor
A new instance of Sequel.
- #job_get_by_id(id) ⇒ Object
- #job_insert(insert_params) ⇒ Object
- #job_insert_many(insert_params_array) ⇒ Object
- #job_list ⇒ Object
- #rollback_exception ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize(db) ⇒ Sequel
Returns a new instance of Sequel.
10 11 12 13 14 |
# File 'lib/driver.rb', line 10 def initialize(db) @db = db @db.extension(:pg_array) @db.extension(:pg_json) end |
Instance Method Details
#job_get_by_id(id) ⇒ Object
16 17 18 19 |
# File 'lib/driver.rb', line 16 def job_get_by_id(id) data_set = @db[:river_job].where(id: id) data_set.first ? to_job_row(data_set.first) : nil end |
#job_insert(insert_params) ⇒ Object
21 22 23 |
# File 'lib/driver.rb', line 21 def job_insert(insert_params) job_insert_many([insert_params]).first end |
#job_insert_many(insert_params_array) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/driver.rb', line 25 def job_insert_many(insert_params_array) @db[:river_job] .insert_conflict( target: [:unique_key], conflict_where: ::Sequel.lit( "unique_key IS NOT NULL AND unique_states IS NOT NULL AND river_job_state_in_bitmask(unique_states, state)" ), update: {kind: ::Sequel[:excluded][:kind]} ) .returning(::Sequel.lit("*, (xmax != 0) AS unique_skipped_as_duplicate")) .multi_insert(insert_params_array.map { |p| insert_params_to_hash(p) }) .map { |row| to_insert_result(row) } end |
#job_list ⇒ Object
39 40 41 42 |
# File 'lib/driver.rb', line 39 def job_list data_set = @db[:river_job].order_by(:id) data_set.all.map { |job| to_job_row(job) } end |
#rollback_exception ⇒ Object
44 45 46 |
# File 'lib/driver.rb', line 44 def rollback_exception ::Sequel::Rollback end |
#transaction ⇒ Object
48 49 50 |
# File 'lib/driver.rb', line 48 def transaction(&) @db.transaction(savepoint: true, &) end |