Class: Sequel::DBI::Database
- Inherits:
-
Sequel::Database
- Object
- Sequel::Database
- Sequel::DBI::Database
- Defined in:
- lib/sequel_core/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::ADAPTERS, 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::NULL, Schema::SQL::PRIMARY_KEY, Schema::SQL::RESTRICT, Schema::SQL::SET_DEFAULT, Schema::SQL::SET_NULL, Schema::SQL::TYPES, Schema::SQL::UNDERSCORE, Schema::SQL::UNIQUE, Schema::SQL::UNSIGNED
Instance Attribute Summary collapse
-
#lowercase ⇒ Object
Converts all column names to lowercase.
Attributes inherited from Sequel::Database
#loggers, #opts, #pool, #quote_identifiers
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, #get, #initialize, #inspect, #log_info, #logger, #logger=, #multi_threaded?, #query, quote_identifiers=, #quote_identifiers?, #rename_column, #rename_table, #select, #serial_primary_key_options, #set_column_default, #set_column_type, single_threaded=, #single_threaded?, #synchronize, #table_exists?, #test_connection, #transaction, #typecast_value, #uri
Methods included from Schema::SQL
#alter_table_sql, #alter_table_sql_list, #auto_increment_sql, #column_definition_sql, #column_list_sql, #constraint_definition_sql, #create_table_sql_list, #default_index_name, #drop_table_sql, #filter_expr, #index_definition_sql, #index_list_sql_list, #literal, #on_delete_clause, #quote_identifier, #rename_table_sql, #schema, #schema_utility_dataset, #type_literal
Constructor Details
This class inherits a constructor from Sequel::Database
Instance Attribute Details
#lowercase ⇒ Object
Converts all column names to lowercase
75 76 77 |
# File 'lib/sequel_core/adapters/dbi.rb', line 75 def lowercase @lowercase ||= false end |
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.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sequel_core/adapters/dbi.rb', line 27 def self.(uri) database = (m = /\/(.*)/.match(uri.path)) && (m[1]) if m = /dbi-(.+)/.match(uri.scheme) adapter = DBI_ADAPTERS[m[1].to_sym] || m[1] database = "#{adapter}:dbname=#{database}" end { :user => uri.user, :password => uri.password, :host => uri.host, :port => uri.port, :database => database } end |
Instance Method Details
#connect ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/sequel_core/adapters/dbi.rb', line 43 def connect dbname = @opts[:database] if dbname !~ /^DBI:/ then dbname = "DBI:#{dbname}" [:host, :port].each{|sym| dbname += ";#{sym}=#{@opts[sym]}" unless @opts[sym].blank?} end ::DBI.connect(dbname, @opts[:user], @opts[:password]) end |
#dataset(opts = nil) ⇒ Object
56 57 58 |
# File 'lib/sequel_core/adapters/dbi.rb', line 56 def dataset(opts = nil) DBI::Dataset.new(self, opts) end |
#disconnect ⇒ Object
52 53 54 |
# File 'lib/sequel_core/adapters/dbi.rb', line 52 def disconnect @pool.disconnect {|c| c.disconnect} end |
#do(sql) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/sequel_core/adapters/dbi.rb', line 67 def do(sql) log_info(sql) @pool.hold do |conn| conn.do(sql) end end |
#execute(sql) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/sequel_core/adapters/dbi.rb', line 60 def execute(sql) log_info(sql) @pool.hold do |conn| conn.execute(sql) end end |