Method: Sequel::Database#initialize

Defined in:
lib/sequel/database/misc.rb

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

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

Accepts 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

:logger

A specific logger to use

:loggers

An array of loggers to use

:quote_identifiers

Whether to quote identifiers

:servers

A hash specifying a server/shard specific options, keyed by shard symbol

:single_threaded

Whether to use a single-threaded connection pool

:sql_log_level

Method to use to log SQL to a logger, :info by default.

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sequel/database/misc.rb', line 42

def initialize(opts = {}, &block)
  @opts ||= opts
  @opts = connection_pool_default_options.merge(@opts)
  @loggers = Array(@opts[:logger]) + Array(@opts[:loggers])
  self.log_warn_duration = @opts[:log_warn_duration]
  @opts[:disconnection_proc] ||= proc{|conn| disconnect_connection(conn)}
  block ||= proc{|server| connect(server)}
  @opts[:servers] = {} if @opts[:servers].is_a?(String)
  @opts[:adapter_class] = self.class
  
  @opts[:single_threaded] = @single_threaded = typecast_value_boolean(@opts.fetch(:single_threaded, @@single_threaded))
  @schemas = {}
  @default_schema = @opts.fetch(:default_schema, default_schema_default)
  @prepared_statements = {}
  @transactions = {}
  @identifier_input_method = nil
  @identifier_output_method = nil
  @quote_identifiers = nil
  @timezone = nil
  @dataset_class = dataset_class_default
  @cache_schema = typecast_value_boolean(@opts.fetch(:cache_schema, true))
  @dataset_modules = []
  self.sql_log_level = @opts[:sql_log_level] ? @opts[:sql_log_level].to_sym : :info
  @pool = ConnectionPool.get_pool(@opts, &block)

  Sequel.synchronize{::Sequel::DATABASES.push(self)}
end