class Pg::Conn
The class to access a PostgreSQL database.
Example¶ ↑
require "pgsql" conn = Pg::Conn.open :dbname => "test1" res = conn.exec "select * from mytable;"
See the Pg::Result class for information on working with the results of a query.
Public Class Methods
Pg::Conn.connect( hash) → conn
click to toggle source
Pg::Conn.connect( str, hash) → conn
Pg::Conn.connect( hash) { |conn| ... } → obj
Pg::Conn.connect( str, hash) { |conn| ... } → obj
Without a block this is the same as +Pg::Conn.new+. If a block is given, the connection will be closed afterwards.
VALUE pgconn_s_connect( int argc, VALUE *argv, VALUE cls) { VALUE pgconn; pgconn = rb_class_new_instance( argc, argv, cls); return rb_block_given_p() ? rb_ensure( rb_yield, pgconn, pgconn_close, pgconn) : pgconn; }
Pg::Conn.parse( str) → hash
click to toggle source
Parse a connection string and return a hash with keys :dbname
,
:user
, :host
, etc.
VALUE pgconn_s_parse( VALUE cls, VALUE str) { VALUE params; params = rb_hash_new(); connstr_to_hash( params, str); return params; }