Class: DB::Client
- Inherits:
-
Object
- Object
- DB::Client
- Defined in:
- lib/db/client.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
Class Method Summary collapse
-
.open(*arguments) {|client, task| ... } ⇒ client
If no block provided.
Instance Method Summary collapse
- #call(statement = nil, **options) ⇒ Object
- #close ⇒ Object
-
#initialize(adapter, **options) ⇒ Client
constructor
A new instance of Client.
- #transaction(statement = "BEGIN", **options) ⇒ Object
Constructor Details
#initialize(adapter, **options) ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 |
# File 'lib/db/client.rb', line 32 def initialize(adapter, **) @adapter = adapter @pool = connect(**) end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
38 39 40 |
# File 'lib/db/client.rb', line 38 def endpoint @endpoint end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
39 40 41 |
# File 'lib/db/client.rb', line 39 def protocol @protocol end |
Class Method Details
.open(*arguments) {|client, task| ... } ⇒ client
Returns if no block provided.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/db/client.rb', line 43 def self.open(*arguments, &block) client = self.new(*arguments) return client unless block_given? Async do |task| begin yield client, task ensure client.close end end.wait end |
Instance Method Details
#call(statement = nil, **options) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/db/client.rb', line 61 def call(statement = nil, **) query = Context::Query.new(@pool, **) if statement query.send_query(statement) end return query unless block_given? begin yield query ensure query.close end end |
#close ⇒ Object
57 58 59 |
# File 'lib/db/client.rb', line 57 def close @pool.close end |
#transaction(statement = "BEGIN", **options) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/db/client.rb', line 77 def transaction(statement = "BEGIN", **) transaction = Context::Transaction.new(@pool, **) if statement transaction.call("BEGIN") end return transaction unless block_given? begin yield transaction transaction.commit ensure transaction.abort if $! end end |