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 183
183:       def initialize(*args)
184:         super
185:         @primary_keys = {}
186:         @primary_key_sequences = {}
187:       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 192
192:       def connect(server)
193:         opts = server_opts(server)
194:         conn = Adapter.connect(
195:           (opts[:host] unless blank_object?(opts[:host])),
196:           opts[:port] || 5432,
197:           nil, '',
198:           opts[:database],
199:           opts[:user],
200:           opts[:password]
201:         )
202:         if encoding = opts[:encoding] || opts[:charset]
203:           if conn.respond_to?(:set_client_encoding)
204:             conn.set_client_encoding(encoding)
205:           else
206:             conn.async_exec("set client_encoding to '#{encoding}'")
207:           end
208:         end
209:         conn.db = self
210:         conn.apply_connection_settings
211:         conn
212:       end

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

[Source]

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

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

[Source]

     # File lib/sequel/adapters/postgres.rb, line 220
220:       def execute(sql, opts={}, &block)
221:         return execute_prepared_statement(sql, opts, &block) if Symbol === sql
222:         begin
223:           log_info(sql, opts[:arguments])
224:           synchronize(opts[:server]){|conn| conn.execute(sql, opts[:arguments], &block)}
225:         rescue => e
226:           log_info(e.message)
227:           raise_error(e, :classes=>CONVERTED_EXCEPTIONS)
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:         begin 
236:           log_info(sql, opts[:arguments])
237:           synchronize(opts[:server]) do |conn|
238:             conn.execute(sql, opts[:arguments])
239:             insert_result(conn, opts[:table], opts[:values])
240:           end
241:         rescue => e
242:           log_info(e.message)
243:           raise_error(e, :classes=>CONVERTED_EXCEPTIONS)
244:         end
245:       end

[Validate]