Class Sequel::Postgres::Database
In: lib/sequel_core/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_core/adapters/postgres.rb, line 186
186:       def initialize(*args)
187:         super
188:         @primary_keys = {}
189:         @primary_key_sequences = {}
190:       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_core/adapters/postgres.rb, line 195
195:       def connect(server)
196:         opts = server_opts(server)
197:         conn = Adapter.connect(
198:           (opts[:host] unless opts[:host].blank?),
199:           opts[:port] || 5432,
200:           nil, '',
201:           opts[:database],
202:           opts[:user],
203:           opts[:password]
204:         )
205:         if encoding = opts[:encoding] || opts[:charset]
206:           if conn.respond_to?(:set_client_encoding)
207:             conn.set_client_encoding(encoding)
208:           else
209:             conn.async_exec("set client_encoding to '#{encoding}'")
210:           end
211:         end
212:         conn.db = self
213:         conn.apply_connection_settings
214:         conn
215:       end

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

[Source]

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

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

[Source]

     # File lib/sequel_core/adapters/postgres.rb, line 223
223:       def execute(sql, opts={}, &block)
224:         return execute_prepared_statement(sql, opts, &block) if Symbol === sql
225:         begin
226:           log_info(sql, opts[:arguments])
227:           synchronize(opts[:server]){|conn| conn.execute(sql, opts[:arguments], &block)}
228:         rescue => e
229:           log_info(e.message)
230:           raise_error(e, :classes=>CONVERTED_EXCEPTIONS)
231:         end
232:       end

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

[Source]

     # File lib/sequel_core/adapters/postgres.rb, line 236
236:       def execute_insert(sql, opts={})
237:         return execute(sql, opts) if Symbol === sql
238:         begin 
239:           log_info(sql, opts[:arguments])
240:           synchronize(opts[:server]) do |conn|
241:             conn.execute(sql, opts[:arguments])
242:             insert_result(conn, opts[:table], opts[:values])
243:           end
244:         rescue => e
245:           log_info(e.message)
246:           raise_error(e, :classes=>CONVERTED_EXCEPTIONS)
247:         end
248:       end

[Validate]