Class Sequel::Postgres::Database
In: lib/sequel/adapters/postgres.rb
Parent: Sequel::Database

Database class for PostgreSQL databases used with Sequel and the pg, postgres, or postgres-pr driver.

Methods

connect   dataset   execute   execute_insert   new  

Included Modules

Sequel::Postgres::DatabaseMethods

Public Class methods

Add the primary_keys and primary_key_sequences instance variables, so we can get the correct return values for inserted rows.

[Source]

     # File lib/sequel/adapters/postgres.rb, line 187
187:       def initialize(*args)
188:         super
189:         @primary_keys = {}
190:         @primary_key_sequences = {}
191:       end

Public Instance methods

Connects to the database. In addition to the standard database options, using the :encoding or :charset option changes the client encoding for the connection.

[Source]

     # File lib/sequel/adapters/postgres.rb, line 196
196:       def connect(server)
197:         opts = server_opts(server)
198:         conn = Adapter.connect(
199:           (opts[:host] unless blank_object?(opts[:host])),
200:           opts[:port] || 5432,
201:           nil, '',
202:           opts[:database],
203:           opts[:user],
204:           opts[:password]
205:         )
206:         if encoding = opts[:encoding] || opts[:charset]
207:           if conn.respond_to?(:set_client_encoding)
208:             conn.set_client_encoding(encoding)
209:           else
210:             conn.async_exec("set client_encoding to '#{encoding}'")
211:           end
212:         end
213:         conn.db = self
214:         conn.apply_connection_settings
215:         conn
216:       end

Return instance of Sequel::Postgres::Dataset with the given options.

[Source]

     # File lib/sequel/adapters/postgres.rb, line 219
219:       def dataset(opts = nil)
220:         Postgres::Dataset.new(self, opts)
221:       end

Execute the given SQL with the given args on an available connection.

[Source]

     # File lib/sequel/adapters/postgres.rb, line 224
224:       def execute(sql, opts={}, &block)
225:         check_database_errors do
226:           return execute_prepared_statement(sql, opts, &block) if Symbol === sql
227:           synchronize(opts[:server]){|conn| conn.execute(sql, opts[:arguments], &block)}
228:         end
229:       end

Insert the values into the table and return the primary key (if automatically generated).

[Source]

     # File lib/sequel/adapters/postgres.rb, line 233
233:       def execute_insert(sql, opts={})
234:         return execute(sql, opts) if Symbol === sql
235:         check_database_errors do
236:           synchronize(opts[:server]) do |conn|
237:             conn.execute(sql, opts[:arguments])
238:             insert_result(conn, opts[:table], opts[:values])
239:           end
240:         end
241:       end

[Validate]