Class: DataObject::Postgres::Connection
- Inherits:
-
Connection
- Object
- Connection
- DataObject::Postgres::Connection
- Defined in:
- lib/do_postgres.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #close ⇒ Object
- #create_command(text) ⇒ Object
-
#initialize(connection_string) ⇒ Connection
constructor
A new instance of Connection.
- #open ⇒ Object
Constructor Details
#initialize(connection_string) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 |
# File 'lib/do_postgres.rb', line 13 def initialize(connection_string) @state = STATE_CLOSED @connection_string = connection_string end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
11 12 13 |
# File 'lib/do_postgres.rb', line 11 def db @db end |
Instance Method Details
#close ⇒ Object
27 28 29 30 31 |
# File 'lib/do_postgres.rb', line 27 def close Postgres_c.PQfinish(@db) @state = STATE_CLOSED true end |
#create_command(text) ⇒ Object
33 34 35 |
# File 'lib/do_postgres.rb', line 33 def create_command(text) Command.new(self, text) end |
#open ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/do_postgres.rb', line 18 def open @db = Postgres_c.PQconnectdb(@connection_string) if Postgres_c.PQstatus(@db) != Postgres_c::CONNECTION_OK raise ConnectionFailed, "The connection with connection string #{@connection_string} failed\n#{Postgres_c.PQerrorMessage(@db)}" end @state = STATE_OPEN true end |