Class: DB::Context::Query
- Inherits:
-
Object
- Object
- DB::Context::Query
- Defined in:
- lib/db/context/query.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #call(statement, **options) ⇒ Object
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(pool, **options) ⇒ Query
constructor
A new instance of Query.
- #next_result ⇒ Object
- #results ⇒ Object
- #send_query(statement, **options) ⇒ Object
Constructor Details
#initialize(pool, **options) ⇒ Query
Returns a new instance of Query.
27 28 29 30 |
# File 'lib/db/context/query.rb', line 27 def initialize(pool, **) @pool = pool @connection = pool.acquire end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
32 33 34 |
# File 'lib/db/context/query.rb', line 32 def connection @connection end |
Instance Method Details
#call(statement, **options) ⇒ Object
52 53 54 55 56 |
# File 'lib/db/context/query.rb', line 52 def call(statement, **) @connection.send_query(statement, **) return @connection.next_result end |
#close ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/db/context/query.rb', line 34 def close if @connection self.flush @pool.release(@connection) @connection = nil end end |
#flush ⇒ Object
66 67 68 69 |
# File 'lib/db/context/query.rb', line 66 def flush until @connection.next_result.nil? end end |
#next_result ⇒ Object
48 49 50 |
# File 'lib/db/context/query.rb', line 48 def next_result @connection.next_result end |
#results ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/db/context/query.rb', line 58 def results while result = self.next_result yield result end return nil end |
#send_query(statement, **options) ⇒ Object
44 45 46 |
# File 'lib/db/context/query.rb', line 44 def send_query(statement, **) @connection.send_query(statement, **) end |