class Session
A connected context for sending queries and reading results.
Definitions
def initialize(pool, **options)
Initialize the query context attached to the given connection pool.
Implementation
def initialize(pool, **options)
@pool = pool
@connection = nil
end
def connect!
Pin a connection to the current session.
Implementation
def connect!
@connection ||= @pool.acquire
end
def close
Flush the connection and then return it to the connection pool.
Implementation
def close
if @connection
@pool.release(@connection)
@connection = nil
end
end
def call(statement, **options)
Send a query to the server.
Signature
-
parameter
statement
String
The SQL query to send.
Implementation
def call(statement, **options)
self.with_connection do |connection|
connection.send_query(statement, **options)
if block_given?
yield connection
elsif result = connection.next_result
return Records.wrap(result)
end
end
end