Class: Alf::Database::Connection
- Inherits:
-
Object
- Object
- Alf::Database::Connection
- Extended by:
- Forwardable
- Defined in:
- lib/alf/database/connection.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #adapter_connection ⇒ Object (also: #open!)
- #assert!(msg = "an assert! assertion failed", &bl) ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #deny!(msg = "a deny! assertion failed", &bl) ⇒ Object
- #fact!(msg = "a fact! assertion failed", &bl) ⇒ Object
-
#initialize(db, options = Options.new, &connection_handler) ⇒ Connection
constructor
A new instance of Connection.
- #migrate! ⇒ Object
- #optimize(*args, &bl) ⇒ Object
-
#parse(*args, &bl) ⇒ Object
logical level.
- #query(*args, &bl) ⇒ Object
- #reconnect(opts = {}) ⇒ Object
- #relvar(*args, &bl) ⇒ Object
-
#to_s ⇒ Object
others.
- #tuple_extract(*args, &bl) ⇒ Object
Constructor Details
#initialize(db, options = Options.new, &connection_handler) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 |
# File 'lib/alf/database/connection.rb', line 7 def initialize(db, = Options.new, &connection_handler) @db = db = .freeze @connection_handler = connection_handler open! end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
13 14 15 |
# File 'lib/alf/database/connection.rb', line 13 def db @db end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/alf/database/connection.rb', line 13 def end |
Instance Method Details
#adapter_connection ⇒ Object Also known as: open!
18 19 20 |
# File 'lib/alf/database/connection.rb', line 18 def adapter_connection @adapter_connection ||= connection_handler.call() end |
#assert!(msg = "an assert! assertion failed", &bl) ⇒ Object
63 64 65 |
# File 'lib/alf/database/connection.rb', line 63 def assert!(msg = "an assert! assertion failed", &bl) relvar(&bl).not_empty!(msg) end |
#close ⇒ Object
35 36 37 38 39 |
# File 'lib/alf/database/connection.rb', line 35 def close adapter_connection.close unless closed? @adapter_connection = nil @parser = nil end |
#closed? ⇒ Boolean
31 32 33 |
# File 'lib/alf/database/connection.rb', line 31 def closed? @adapter_connection.nil? end |
#deny!(msg = "a deny! assertion failed", &bl) ⇒ Object
67 68 69 |
# File 'lib/alf/database/connection.rb', line 67 def deny!(msg = "a deny! assertion failed", &bl) relvar(&bl).empty!(msg) end |
#fact!(msg = "a fact! assertion failed", &bl) ⇒ Object
71 72 73 74 75 |
# File 'lib/alf/database/connection.rb', line 71 def fact!(msg = "a fact! assertion failed", &bl) relvar(&bl).tuple_extract rescue NoSuchTupleError raise FactAssertionError, msg end |
#migrate! ⇒ Object
89 90 91 |
# File 'lib/alf/database/connection.rb', line 89 def migrate! adapter_connection.migrate!() end |
#optimize(*args, &bl) ⇒ Object
47 48 49 |
# File 'lib/alf/database/connection.rb', line 47 def optimize(*args, &bl) optimizer.call(parse(*args, &bl)) end |
#parse(*args, &bl) ⇒ Object
logical level
43 44 45 |
# File 'lib/alf/database/connection.rb', line 43 def parse(*args, &bl) Algebra::Operand.coerce parser.parse(*args, &bl) end |
#query(*args, &bl) ⇒ Object
55 56 57 |
# File 'lib/alf/database/connection.rb', line 55 def query(*args, &bl) relvar(*args, &bl).to_relation end |
#reconnect(opts = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/alf/database/connection.rb', line 24 def reconnect(opts = {}) close unless (opts.keys & [:schema_cache]).empty? = .merge(opts) @parser = nil open! end |
#relvar(*args, &bl) ⇒ Object
51 52 53 |
# File 'lib/alf/database/connection.rb', line 51 def relvar(*args, &bl) optimize(*args, &bl).to_relvar end |
#to_s ⇒ Object
others
95 96 97 |
# File 'lib/alf/database/connection.rb', line 95 def to_s "Alf::Database::Connection(#{adapter_connection})" end |
#tuple_extract(*args, &bl) ⇒ Object
59 60 61 |
# File 'lib/alf/database/connection.rb', line 59 def tuple_extract(*args, &bl) relvar(*args, &bl).tuple_extract end |