Class/Module Index [+]

Quicksearch

Sequel::Postgres::Database

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

Public Class Methods

new(*args) click to toggle source

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

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

Public Instance Methods

connect(server) click to toggle source

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

# File lib/sequel/adapters/postgres.rb, line 196
def connect(server)
  opts = server_opts(server)
  conn = Adapter.connect(
    (opts[:host] unless blank_object?(opts[:host])),
    opts[:port] || 5432,
    nil, '',
    opts[:database],
    opts[:user],
    opts[:password]
  )
  if encoding = opts[:encoding] || opts[:charset]
    if conn.respond_to?(:set_client_encoding)
      conn.set_client_encoding(encoding)
    else
      conn.async_exec("set client_encoding to '#{encoding}'")
    end
  end
  conn.db = self
  conn.apply_connection_settings
  conn
end
dataset(opts = nil) click to toggle source

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

# File lib/sequel/adapters/postgres.rb, line 219
def dataset(opts = nil)
  Postgres::Dataset.new(self, opts)
end
execute(sql, opts={}, &block) click to toggle source

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

# File lib/sequel/adapters/postgres.rb, line 224
def execute(sql, opts={}, &block)
  check_database_errors do
    return execute_prepared_statement(sql, opts, &block) if Symbol === sql
    synchronize(opts[:server]){|conn| conn.execute(sql, opts[:arguments], &block)}
  end
end
execute_insert(sql, opts={}) click to toggle source

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.