Class: Oculus::Connection::Postgres

Inherits:
Object
  • Object
show all
Defined in:
lib/oculus/connection/postgres.rb

Instance Method Summary collapse

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(options = {})
  @connection = ::PG::Connection.new(options[:host],
                                     options[:port],
                                     nil, nil,
                                     options[:database],
                                     options[:username],
                                     options[: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.message)
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_idObject



26
27
28
# File 'lib/oculus/connection/postgres.rb', line 26

def thread_id
  @connection.backend_pid
end