Class: Oculus::Connection::Postgres
- Inherits:
-
Object
- Object
- Oculus::Connection::Postgres
- Defined in:
- lib/oculus/connection/postgres.rb
Instance Method Summary collapse
- #execute(sql) ⇒ Object
-
#initialize(options = {}) ⇒ Postgres
constructor
A new instance of Postgres.
- #kill(id) ⇒ Object
- #thread_id ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Postgres
Returns a new instance of Postgres.
6 7 8 9 10 11 12 13 |
# File 'lib/oculus/connection/postgres.rb', line 6 def initialize( = {}) @connection = ::PG::Connection.new([:host], [:port], nil, nil, [:database], [:username], [:password]) end |
Instance Method Details
#execute(sql) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/oculus/connection/postgres.rb', line 15 def execute(sql) results = @connection.exec(sql) [results.fields] + results.values if results rescue ::PG::Error => e raise Connection::Error.new(e.) end |
#kill(id) ⇒ Object
22 23 24 |
# File 'lib/oculus/connection/postgres.rb', line 22 def kill(id) @connection.execute("SELECT pg_cancel_backend(#{id})") end |
#thread_id ⇒ Object
26 27 28 |
# File 'lib/oculus/connection/postgres.rb', line 26 def thread_id @connection.backend_pid end |