Class: DB::DBPool::DBAttempt

Inherits:
Object
  • Object
show all
Defined in:
backend/app/model/db.rb

Instance Method Summary collapse

Constructor Details

#initialize(happy_path) ⇒ DBAttempt

Returns a new instance of DBAttempt.



280
281
282
# File 'backend/app/model/db.rb', line 280

def initialize(happy_path)
  @happy_path = happy_path
end

Instance Method Details

#and_if_constraint_fails(&failed_path) ⇒ Object



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'backend/app/model/db.rb', line 285

def and_if_constraint_fails(&failed_path)
  begin
    DB.transaction(:savepoint => DB.needs_savepoint?) do
      @happy_path.call
    end
  rescue Sequel::DatabaseError => ex
    if DB.is_integrity_violation(ex)
      failed_path.call(ex)
    else
      raise ex
    end
  rescue Sequel::ValidationFailed => ex
    failed_path.call(ex)
  end
end