 class ActiveRecor8b7c:f320:99b9:690f:4595:cd17:293a:c069Middlewar8b7c:f320:99b9:690f:4595:cd17:293a:c069DatabaseSelector 

Parent:
Object
  The DatabaseSelector Middleware provides a framework for automatically swapping from the primary to the replica database connection. Rails provides a basic framework to determine when to swap and allows for applications to write custom strategy classes to override the default behavior. The resolver class defines when the application should switch (i.e. read from the primary if a write occurred less than 2 seconds ago) and a resolver context class that sets a value that helps the resolver class decide when to switch. Rails default middleware uses the request's session to set a timestamp that informs the application when to read from a primary or read from a replica. To use the DatabaseSelector in your application with default settings add the following options to your environment config: # This require is only necessary when using `rails new app --minimal`
require "active_support/core_ext/integer/time"

class Application < Rails8b7c:f320:99b9:690f:4595:cd17:293a:c069pplication
  config.active_record.database_selector = { delay: 2.seconds }
  config.active_record.database_resolver = ActiveRecor8b7c:f320:99b9:690f:4595:cd17:293a:c069Middlewar8b7c:f320:99b9:690f:4595:cd17:293a:c069DatabaseSelector8b7c:f320:99b9:690f:4595:cd17:293a:c069Resolver
  config.active_record.database_resolver_context = ActiveRecor8b7c:f320:99b9:690f:4595:cd17:293a:c069Middlewar8b7c:f320:99b9:690f:4595:cd17:293a:c069DatabaseSelector8b7c:f320:99b9:690f:4595:cd17:293a:c069Resolver8b7c:f320:99b9:690f:4595:cd17:293a:c069Session
end
 New applications will include these lines commented out in the production.rb. The default behavior can be changed by setting the config options to a custom class: config.active_record.database_selector = { delay: 2.seconds }
config.active_record.database_resolver = MyResolver
config.active_record.database_resolver_context = MyResolver8b7c:f320:99b9:690f:4595:cd17:293a:c069MySession
     Attributes    context_klass[R]     options[R]     resolver_klass[R]      Public Class Methods    new(app, resolver_klass = nil, context_klass = nil, options = {}) Show source  
 # File activerecord/lib/active_record/middleware/database_selector.rb, line 43
def initialize(app, resolver_klass = nil, context_klass = nil, options = {})
  @app = app
  @resolver_klass = resolver_klass || Resolver
  @context_klass = context_klass || Resolver8b7c:f320:99b9:690f:4595:cd17:293a:c069Session
  @options = options
end       Public Instance Methods    call(env) Show source  
 # File activerecord/lib/active_record/middleware/database_selector.rb, line 54
def call(env)
  request = ActionDispatch8b7c:f320:99b9:690f:4595:cd17:293a:c069Request.new(env)

  select_database(request) do
    @app.call(env)
  end
end  Middleware that determines which database connection to use in a multiple database application.    

    
{'path': 'public/docs/rails~7.0/activerecord/middleware/databaseselector.html', 'source': 'DevDocs.IO'}