Class: Alf::Database
- Inherits:
-
Object
- Object
- Alf::Database
- Defined in:
- lib/alf/database.rb,
lib/alf/database/options.rb,
lib/alf/database/connection.rb
Defined Under Namespace
Classes: Connection, Options
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
Class Method Summary collapse
- .connect(conn_spec, options = {}, &bl) ⇒ Object
- .new(conn_spec, options = {}) {|options| ... } ⇒ Object
Instance Method Summary collapse
- #connect(opts = {}) ⇒ Object
-
#connection(opts = {}) ⇒ Object
connection handling.
-
#initialize(adapter, options) ⇒ Database
constructor
A new instance of Database.
Constructor Details
#initialize(adapter, options) ⇒ Database
Returns a new instance of Database.
19 20 21 22 23 |
# File 'lib/alf/database.rb', line 19 def initialize(adapter, ) @adapter = adapter @default_options = .freeze @schema_cache = Adapter::Connection::SchemaCached.empty_cache end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
24 25 26 |
# File 'lib/alf/database.rb', line 24 def adapter @adapter end |
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
24 25 26 |
# File 'lib/alf/database.rb', line 24 def @default_options end |
Class Method Details
.connect(conn_spec, options = {}, &bl) ⇒ Object
14 15 16 17 |
# File 'lib/alf/database.rb', line 14 def self.connect(conn_spec, = {}, &bl) db = new(conn_spec, ) bl ? db.connect(&bl) : db.connection end |
Instance Method Details
#connect(opts = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/alf/database.rb', line 38 def connect(opts = {}) c = connection(opts) yield(c) ensure c.close if c end |
#connection(opts = {}) ⇒ Object
connection handling
28 29 30 31 32 33 34 35 36 |
# File 'lib/alf/database.rb', line 28 def connection(opts = {}) Connection.new(self, .merge(opts)) do |conn_opts| conn = adapter.connection if conn_opts.schema_cache? conn = Adapter::Connection::SchemaCached.new(conn, @schema_cache) end conn end end |