class Sequel::Swift::Database

Constants

DatasetClass

Attributes

swift_class[RW]

The Swift adapter class being used by this database. Connections in this database's connection pool will be instances of this class.

Public Class Methods

new(opts=OPTS) click to toggle source
Calls superclass method Sequel::Database.new
# File lib/sequel/adapters/swift.rb, line 41
def initialize(opts=OPTS)
  Sequel.require "adapters/swift/#{opts[:db_type]}" if %w'postgres mysql sqlite'.include?(opts[:db_type].to_s)
  super
end

Public Instance Methods

connect(server) click to toggle source

Create an instance of #swift_class for the given options.

# File lib/sequel/adapters/swift.rb, line 47
def connect(server)
  opts = server_opts(server)
  opts[:pass] = opts[:password]
  setup_connection(swift_class.new(opts))
end
execute(sql, opts=OPTS) { |res| ... } click to toggle source

Execute the given SQL, yielding a Swift::Result if a block is given.

# File lib/sequel/adapters/swift.rb, line 54
def execute(sql, opts=OPTS)
  synchronize(opts[:server]) do |conn|
    begin
      res = log_connection_yield(sql, conn){conn.execute(sql)}
      yield res if block_given?
      nil
    rescue ::Swift::Error => e
      raise_error(e)
    end
  end
end
execute_dui(sql, opts=OPTS) click to toggle source

Execute the SQL on the this database, returning the number of affected rows.

# File lib/sequel/adapters/swift.rb, line 68
def execute_dui(sql, opts=OPTS)
  synchronize(opts[:server]) do |conn|
    begin
      log_connection_yield(sql, conn){conn.execute(sql).affected_rows}
    rescue ::Swift::Error => e
      raise_error(e)
    end
  end
end
execute_insert(sql, opts=OPTS) click to toggle source

Execute the SQL on this database, returning the primary key of the table being inserted to.

# File lib/sequel/adapters/swift.rb, line 80
def execute_insert(sql, opts=OPTS)
  synchronize(opts[:server]) do |conn|
    begin
      log_connection_yield(sql, conn){conn.execute(sql).insert_id}
    rescue ::Swift::Error => e
      raise_error(e)
    end
  end
end

Private Instance Methods

adapter_initialize() click to toggle source

Call the DATABASE_SETUP proc directly after initialization, so the object always uses sub adapter specific code. Also, raise an error immediately if the connection doesn't have a db_type specified, since one is required to include the correct subadapter.

# File lib/sequel/adapters/swift.rb, line 97
def adapter_initialize
  if db_type = @opts[:db_type] and !db_type.to_s.empty? 
    if prok = DATABASE_SETUP[db_type.to_s.to_sym]
      prok.call(self)
    else
      raise(Error, "No :db_type option specified")
    end
  else
    raise(Error, ":db_type option not valid, should be postgres, mysql, or sqlite")
  end
end
connection_execute_method() click to toggle source

Method to call on a statement object to execute SQL that does not return any rows.

# File lib/sequel/adapters/swift.rb, line 111
def connection_execute_method
  :execute
end
database_error_classes() click to toggle source
# File lib/sequel/adapters/swift.rb, line 115
def database_error_classes
  [::Swift::Error]
end
server_opts(o) click to toggle source

Set the :db entry to the same as the :database entry, since Swift uses :db.

Calls superclass method Sequel::Database#server_opts
# File lib/sequel/adapters/swift.rb, line 121
def server_opts(o)
  o = super
  o[:db] ||= o[:database]
  o
end
setup_connection(conn) click to toggle source

Allow extending the given connection when it is first created. By default, just returns the connection.

# File lib/sequel/adapters/swift.rb, line 129
def setup_connection(conn)
  conn
end