Method: Sequel::Database#initialize

Defined in:
lib/sequel/database.rb

#initialize(opts = {}, &block) ⇒ Database

Constructs a new instance of a database connection with the specified options hash.

Sequel::Database is an abstract class that is not useful by itself.

Takes the following options:

  • :default_schema : The default schema to use, should generally be nil

  • :disconnection_proc: A proc used to disconnect the connection.

  • :identifier_input_method: A string method symbol to call on identifiers going into the database

  • :identifier_output_method: A string method symbol to call on identifiers coming from the database

  • :loggers : An array of loggers to use.

  • :quote_identifiers : Whether to quote identifiers

  • :single_threaded : Whether to use a single-threaded connection pool

All options given are also passed to the ConnectionPool. If a block is given, it is used as the connection_proc for the ConnectionPool.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sequel/database.rb', line 68

def initialize(opts = {}, &block)
  @opts ||= opts
  
  @single_threaded = opts.include?(:single_threaded) ? opts[:single_threaded] : @@single_threaded
  @schemas = nil
  @default_schema = opts.include?(:default_schema) ? opts[:default_schema] : default_schema_default
  @prepared_statements = {}
  @transactions = []
  @identifier_input_method = nil
  @identifier_output_method = nil
  @quote_identifiers = nil
  if opts.include?(:upcase_identifiers)
    Deprecation.deprecate('The :upcase_identifiers Database option', 'Use the :identifier_input_method => :upcase option instead')
    @identifier_input_method = opts[:upcase_identifiers] ? :upcase : ""
  end
  @pool = (@single_threaded ? SingleThreadedPool : ConnectionPool).new(connection_pool_default_options.merge(opts), &block)
  @pool.connection_proc = proc{|server| connect(server)} unless block
  @pool.disconnection_proc = proc{|conn| disconnect_connection(conn)} unless opts[:disconnection_proc]

  @loggers = Array(opts[:logger]) + Array(opts[:loggers])
  ::Sequel::DATABASES.push(self)
end