New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sequel-activerecord-adapter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequel-activerecord-adapter

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Sequel ActiveRecord Adapter

This gem allows the Sequel library to reuse an existing ActiveRecord connection. It supports postgresql, mysql2 and sqlite3 adapters.

This can be useful if you're using a library that uses Sequel for database interaction (e.g. Rodauth), but you want to avoid creating a separate database connection. Or if you're transitioning from ActiveRecord to Sequel, and want the database connection to be reused.

Note that this is a best-effort implementation, so some discrepancies are still possible. However, it's worth mentioning that this gem passes Rodauth's test suite for all adapters, which has some pretty advanced Sequel usage.

Installation

Add this line to your application's Gemfile:

gem "sequel-activerecord-adapter"

And then execute:

$ bundle install

Or install it yourself as:

$ gem install sequel-activerecord-adapter

Usage

Given you've configured your ActiveRecord connection, you can create a Sequel database and start making queries:

require "sequel-activerecord-adapter"

DB = Sequel.activerecord
DB.create_table :posts do
  primary_key :id
  String :title, null: false
  Stirng :body, null: false
end

DB[:posts].insert(
  title: "Sequel ActiveRecord Adapter",
  body:  "Allows Sequel to reuse ActiveRecord's connection",
)
#=> 1

DB[:posts].all
#=> [{ title: "Sequel ActiveRecord Adapter", body: "Allows Sequel to reuse ActiveRecord's connection" }]

DB[:posts].update(title: "Sequel Active Record Adapter")
#=> 1

Since Sequel is using ActiveRecord connection object to make queries, any SQL queries will be logged to the ActiveRecord logger.

Configuration

By default, the connection configuration will be read from ActiveRecord::Base. If you want to use connection configuration from a different model, you can pass the model class:

class MyModel < ActiveRecord::Base
  connects_to database: { writing: :animals, reading: :animals_replica }
end
Sequel.activerecord(MyModel)

If the correct adapter cannot be inferred from ActiveRecord configuration at the time of initialization, you can always specify it explicitly:

Sequel.activerecord(adapter: "postgresql")

Tests

The Rakefile has rake tasks for setting up and tearing down different databases, which you need to run first.

Then you can run the tests:

$ rake test

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Sequel::Activerecord::Adapter project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

FAQs

Package last updated on 27 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc