DEV Community

Janko Marohnić
Janko Marohnić

Posted on

1

sequel-activerecord_connection now fully supports Sequel's transaction API

A while ago I created the sequel-activerecord_connection gem, which allows you to use Sequel alongside ActiveRecord and reuse the same database connection. This makes it easier to try Sequel out or use libraries that depend on Sequel (e.g. Rodauth) in ActiveRecord-based projects.

Originally the transaction support was partially implemented, where the most common Sequel transaction options were emulated with the ActiveRecord API. In the latest version I've rewritten the transaction code to fully support Sequel's transaction API, including transaction/savepoint hooks.

require "sequel"

DB = Sequel.postgres(test: false) # avoid creating a database connection
DB.extension :activerecord_connection # use ActiveRecord's database connection

DB.transaction(isolation: :serializable) do # handles isolation levels
  DB.after_commit { ... } # runs after transaction commits
  DB.transaction(savepoint: true) do # creates a savepoint
    DB.after_rollback { ... } # runs after savepoint rolls back
  end
  DB.in_transaction? #=> true
end
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay