Class: Sequel::DBI::Database
- Inherits:
-
Sequel::Database
- Object
- Sequel::Database
- Sequel::DBI::Database
- Defined in:
- lib/sequel/adapters/dbi.rb
Constant Summary collapse
- DBI_ADAPTERS =
{ :ado => "ADO", :db2 => "DB2", :frontbase => "FrontBase", :interbase => "InterBase", :msql => "Msql", :mysql => "Mysql", :odbc => "ODBC", :oracle => "Oracle", :pg => "Pg", :proxy => "Proxy", :sqlite => "SQLite", :sqlrelay => "SQLRelay" }
Constants inherited from Sequel::Database
Sequel::Database::SQL_BEGIN, Sequel::Database::SQL_COMMIT, Sequel::Database::SQL_ROLLBACK
Constants included from Schema::SQL
Schema::SQL::AUTOINCREMENT, Schema::SQL::CASCADE, Schema::SQL::COMMA_SEPARATOR, Schema::SQL::NOT_NULL, Schema::SQL::NO_ACTION, Schema::SQL::PRIMARY_KEY, Schema::SQL::RESTRICT, Schema::SQL::SET_DEFAULT, Schema::SQL::SET_NULL, Schema::SQL::TYPES, Schema::SQL::UNDERSCORE, Schema::SQL::UNIQUE
Instance Attribute Summary
Attributes inherited from Sequel::Database
Class Method Summary collapse
-
.uri_to_options(uri) ⇒ Object
Converts a uri to an options hash.
Instance Method Summary collapse
- #connect ⇒ Object
- #dataset(opts = nil) ⇒ Object
- #disconnect ⇒ Object
- #do(sql) ⇒ Object
- #execute(sql) ⇒ Object
Methods inherited from Sequel::Database
#<<, #[], adapter_class, adapter_scheme, #add_column, #add_index, #alter_table, connect, #create_or_replace_view, #create_table, #create_table!, #create_view, #drop_column, #drop_index, #drop_table, #drop_view, #fetch, #from, #initialize, #multi_threaded?, #query, #rename_column, #rename_table, #select, #serial_primary_key_options, set_adapter_scheme, #set_column_default, #set_column_type, single_threaded=, #single_threaded?, #synchronize, #table_exists?, #test_connection, #transaction, #uri
Methods included from Schema::SQL
#alter_table_sql, #alter_table_sql_list, #auto_increment_sql, #column_definition_sql, #column_list_sql, #create_table_sql_list, #default_index_name, #drop_table_sql, #index_definition_sql, #index_list_sql_list, #literal, #on_delete_clause, #rename_table_sql, #schema_utility_dataset
Constructor Details
This class inherits a constructor from Sequel::Database
Class Method Details
.uri_to_options(uri) ⇒ Object
Converts a uri to an options hash. These options are then passed to a newly created database object.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sequel/adapters/dbi.rb', line 25 def self.(uri) database = (uri.path =~ /\/(.*)/) && ($1) if uri.scheme =~ /dbi-(.+)/ adapter = DBI_ADAPTERS[$1.to_sym] || $1 database = "#{adapter}:#{database}" end { :user => uri.user, :password => uri.password, :host => uri.host, :port => uri.port, :database => database } end |
Instance Method Details
#connect ⇒ Object
41 42 43 44 45 |
# File 'lib/sequel/adapters/dbi.rb', line 41 def connect dbname = @opts[:database] dbname = 'DBI:' + dbname unless dbname =~ /^DBI:/ ::DBI.connect(dbname, @opts[:user], @opts[:password]) end |
#dataset(opts = nil) ⇒ Object
51 52 53 |
# File 'lib/sequel/adapters/dbi.rb', line 51 def dataset(opts = nil) DBI::Dataset.new(self, opts) end |
#disconnect ⇒ Object
47 48 49 |
# File 'lib/sequel/adapters/dbi.rb', line 47 def disconnect @pool.disconnect {|c| c.disconnect} end |
#do(sql) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/sequel/adapters/dbi.rb', line 62 def do(sql) @logger.info(sql) if @logger @pool.hold do |conn| conn.do(sql) end end |
#execute(sql) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/sequel/adapters/dbi.rb', line 55 def execute(sql) @logger.info(sql) if @logger @pool.hold do |conn| conn.execute(sql) end end |