Module: Sequel::Swift::Postgres::DatabaseMethods

Includes:
Postgres::DatabaseMethods
Defined in:
lib/sequel/adapters/swift/postgres.rb

Overview

Methods to add to Database instances that access PostgreSQL via Swift.

Constant Summary

Constants included from Postgres::DatabaseMethods

Postgres::DatabaseMethods::EXCLUDE_SCHEMAS, Postgres::DatabaseMethods::PREPARED_ARG_PLACEHOLDER, Postgres::DatabaseMethods::RE_CURRVAL_ERROR, Postgres::DatabaseMethods::SYSTEM_TABLE_REGEXP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Postgres::DatabaseMethods

#commit_prepared_transaction, #create_function, #create_language, #create_trigger, #database_type, #drop_function, #drop_language, #drop_table, #drop_trigger, #indexes, #locks, #primary_key, #primary_key_sequence, #reset_primary_key_sequence, #rollback_prepared_transaction, #serial_primary_key_options, #server_version, #supports_prepared_transactions?, #supports_savepoints?, #supports_transaction_isolation_levels?, #table_exists?, #tables

Class Method Details

.extended(db) ⇒ Object

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



37
38
39
40
41
42
# File 'lib/sequel/adapters/swift/postgres.rb', line 37

def self.extended(db)
  db.instance_eval do
    @primary_keys = {}
    @primary_key_sequences = {}
  end
end

Instance Method Details

#dataset(opts = nil) ⇒ Object

Return instance of Sequel::Swift::Postgres::Dataset with the given opts.



45
46
47
# File 'lib/sequel/adapters/swift/postgres.rb', line 45

def dataset(opts=nil)
  Sequel::Swift::Postgres::Dataset.new(self, opts)
end

#execute(sql, opts = {}) ⇒ Object

Run the SELECT SQL on the database and yield the rows



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sequel/adapters/swift/postgres.rb', line 50

def execute(sql, opts={})
  synchronize(opts[:server]) do |conn|
    begin
      res = conn.execute(sql)
      yield res if block_given?
      nil
    rescue SwiftError => e
      raise_error(e)
    end
  end
end

#execute_dui(sql, opts = {}) ⇒ Object

Run the DELETE/UPDATE SQL on the database and return the number of matched rows.



64
65
66
67
68
69
70
71
72
# File 'lib/sequel/adapters/swift/postgres.rb', line 64

def execute_dui(sql, opts={})
  synchronize(opts[:server]) do |conn|
    begin
      conn.execute(sql).rows
    rescue SwiftError => e
      raise_error(e)
    end
  end
end

#execute_insert(sql, opts = {}) ⇒ Object

Run the INSERT SQL on the database and return the primary key for the record.



76
77
78
79
80
81
82
83
84
85
# File 'lib/sequel/adapters/swift/postgres.rb', line 76

def execute_insert(sql, opts={})
  synchronize(opts[:server]) do |conn|
    begin
      conn.execute(sql)
      insert_result(conn, opts[:table], opts[:values])
    rescue SwiftError => e
      raise_error(e)
    end
  end
end