Class: PGconn

Inherits:
Object
  • Object
show all
Defined in:
lib/postgres-pr/postgres-compat.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, options, tty, database, user, auth) ⇒ PGconn

Returns a new instance of PGconn.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/postgres-pr/postgres-compat.rb', line 11

def initialize(host, port, options, tty, database, user, auth)
  uri =
  if host.nil?
    nil
  elsif host[0] != ?/
    "tcp://#{ host }:#{ port }"
  else
    "unix:#{ host }/.s.PGSQL.#{ port }"
  end

  @db = database
  @conn = PostgresPR::Connection.new(database, user, auth, uri)
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



25
26
27
# File 'lib/postgres-pr/postgres-compat.rb', line 25

def db
  @db
end

Class Method Details

.escape(str) ⇒ Object



33
34
35
36
# File 'lib/postgres-pr/postgres-compat.rb', line 33

def self.escape(str)
  # TODO: correct?
  str.gsub(/\\/){ '\\\\' }.gsub(/'/){ '\\\'' }
end

Instance Method Details

#query(sql) ⇒ Object Also known as: exec



27
28
29
# File 'lib/postgres-pr/postgres-compat.rb', line 27

def query(sql)
  PGresult.new(@conn.query(sql))
end