Class: Async::Postgres::Connection
- Inherits:
-
Wrapper
- Object
- Wrapper
- Async::Postgres::Connection
show all
- Defined in:
- lib/async/postgres/connection.rb
Instance Method Summary
collapse
Constructor Details
#initialize(connection_string, reactor = nil) ⇒ Connection
Returns a new instance of Connection.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/async/postgres/connection.rb', line 28
def initialize(connection_string, reactor = nil)
@connection = PG::Connection.connect_start(connection_string)
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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
80
81
82
|
# File 'lib/async/postgres/connection.rb', line 80
def method_missing(*args)
@connection.send(*args)
end
|
Instance Method Details
#async_exec(*args) ⇒ Object
Also known as:
exec
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/async/postgres/connection.rb', line 50
def async_exec(*args)
@connection.send_query(*args)
last_result = result = true
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
|
#respond_to?(*args) ⇒ Boolean
76
77
78
|
# File 'lib/async/postgres/connection.rb', line 76
def respond_to?(*args)
@connection.respond_to(*args)
end
|