DEV Community

Janko Marohnić
Janko Marohnić

Posted on

Just released sequel-activerecord-adapter gem

Sequel is a superb database library for Ruby. However, it can be difficult to get started with it in an app that already uses ActiveRecord, because Sequel requires its own database connection.

So I've created the sequel-activerecord-adapter gem that allows Sequel to reuse the existing ActiveRecord connection for its database interaction.

require "sequel-activerecord-adapter"

ActiveRecord::Base.establish_connection("postgresql:///mydb")

DB = Sequel.activerecord # reuses the ActiveRecord connection

DB.tables #=> [:users, :articles, ...]

DB[:articles].insert(title: "Sequel ActiveRecord Adapter")
DB[:articles].all #=> [{ title: "Sequel ActiveRecord Adapter" }]
DB[:articles].update(author_id: 2)
Enter fullscreen mode Exit fullscreen mode

This means you can now easily use Sequel in parts of your app that might be more performance-sensitive or require more advanced database queries that ActiveRecord doesn't support.

It also means you can use libraries like Rodauth that use Sequel under-the-hood without increased performance and mental overhead that would come with separate database connections.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs