Module: Plutonium::Auth::SequelAdapter
- Defined in:
- lib/plutonium/auth/sequel_adapter.rb
Overview
Provides runtime detection of the database adapter for Sequel configuration. This module dynamically detects the ActiveRecord adapter and returns the corresponding Sequel adapter, allowing users to change their database without needing to regenerate rodauth files.
Constant Summary collapse
- SEQUEL_ADAPTERS =
Maps ActiveRecord adapter names to their corresponding Sequel adapter names. JRuby uses JDBC adapters which have different naming conventions.
{ "postgresql" => (RUBY_ENGINE == "jruby") ? "postgresql" : "postgres", "mysql2" => (RUBY_ENGINE == "jruby") ? "mysql" : "mysql2", "sqlite3" => "sqlite", "oracle_enhanced" => "oracle", "sqlserver" => (RUBY_ENGINE == "jruby") ? "mssql" : "tinytds" }.freeze
Class Method Summary collapse
-
.db ⇒ Sequel::Database
Returns a Sequel database connection that reuses ActiveRecord’s connection.
-
.sequel_adapter ⇒ String
Returns the Sequel adapter name based on the current ActiveRecord adapter.
Class Method Details
.db ⇒ Sequel::Database
Returns a Sequel database connection that reuses ActiveRecord’s connection. Automatically detects the correct adapter based on the current ActiveRecord config.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/plutonium/auth/sequel_adapter.rb', line 26 def db require "sequel/core" adapter = sequel_adapter begin if RUBY_ENGINE == "jruby" Sequel.connect("jdbc:#{adapter}://", extensions: :activerecord_connection, keep_reference: false) else Sequel.public_send(adapter, extensions: :activerecord_connection, keep_reference: false) end rescue => e raise "Failed to initialize Sequel with adapter '#{adapter}'. " \ "Please ensure your database configuration is correct and the required " \ "database gems are installed. Original error: #{e.}" end end |
.sequel_adapter ⇒ String
Returns the Sequel adapter name based on the current ActiveRecord adapter. If the ActiveRecord adapter is not in the SEQUEL_ADAPTERS mapping, the ActiveRecord adapter name is returned as-is, which may work for adapters where the names match between ActiveRecord and Sequel.
48 49 50 |
# File 'lib/plutonium/auth/sequel_adapter.rb', line 48 def sequel_adapter SEQUEL_ADAPTERS[activerecord_adapter] || activerecord_adapter end |