class Async::Sequel::Postgres::Adapter
Public Class Methods
new(database, connection_specification, reactor = nil)
click to toggle source
Calls superclass method
# File lib/async/sequel/postgres/adapter.rb, line 29 def initialize(database, connection_specification, reactor = nil) @connection = ::Sequel::Postgres::Adapter.connect_start(connection_specification) @db = database @connection.instance_variable_set(:@db, database) @connection.instance_variable_set(:@prepared_statements, {}) super(@connection.socket_io, reactor) status = @connection.connect_poll while true if status == PG::PGRES_POLLING_FAILED raise PG::Error.new(@connection.error_message) elsif status == PG::PGRES_POLLING_READING self.wait_readable elsif(status == PG::PGRES_POLLING_WRITING) self.wait_writable elsif status == PG::PGRES_POLLING_OK break end status = @connection.connect_poll end end
Public Instance Methods
async_exec(*args) { |result| ... }
click to toggle source
# File lib/async/sequel/postgres/adapter.rb, line 55 def async_exec(*args) @connection.send_query(*args) last_result = result = true Async.logger.info(self) {args} while true wait_readable @connection.consume_input while @connection.is_busy == false if result = @connection.get_result last_result = result yield result if block_given? else return last_result end end end ensure @connection.get_result until result.nil? end
Also aliased as: exec
execute(sql, args=nil) { |q| ... }
click to toggle source
Execute the given SQL with this connection. If a block is given, yield the results, otherwise, return the number of changed rows.
# File lib/async/sequel/postgres/adapter.rb, line 85 def execute(sql, args=nil) args = args.map{|v| @db.bound_variable_arg(v, self)} if args q = check_disconnect_errors{execute_query(sql, args)} begin block_given? ? yield(q) : q.cmd_tuples ensure q.clear if q && q.respond_to?(:clear) end end
execute_query(sql, args)
click to toggle source
Return the PGResult containing the query results.
# File lib/async/sequel/postgres/adapter.rb, line 96 def execute_query(sql, args) @db.log_connection_yield(sql, self, args){args ? self.async_exec(sql, args) : self.async_exec(sql)} end
method_missing(*args, &block)
click to toggle source
# File lib/async/sequel/postgres/adapter.rb, line 104 def method_missing(*args, &block) # Async.logger.info(self) {args} @connection.send(*args, &block) end
respond_to?(*args)
click to toggle source
# File lib/async/sequel/postgres/adapter.rb, line 100 def respond_to?(*args) @connection.respond_to?(*args) end