Method: Sequel::Database#initialize

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

#initialize(opts = OPTS, &block) ⇒ Database

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

Accepts the following options:

:default_string_column_size

The default size of string columns, 255 by default.

: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.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/sequel/database/misc.rb', line 113

def initialize(opts = 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]
  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, Database.single_threaded))
  @schemas = {}
  @default_string_column_size = @opts[:default_string_column_size] || DEFAULT_STRING_COLUMN_SIZE
  @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 = []
  @schema_type_classes = SCHEMA_TYPE_CLASSES.dup
  self.sql_log_level = @opts[:sql_log_level] ? @opts[:sql_log_level].to_sym : :info
  @pool = ConnectionPool.get_pool(self, @opts)

  reset_identifier_mangling
  adapter_initialize

  unless typecast_value_boolean(@opts[:keep_reference]) == false
    Sequel.synchronize{::Sequel::DATABASES.push(self)}
  end
  Sequel::Database.run_after_initialize(self)
end