class Sequel::DataObjects::Database

DataObjects uses it's own internal connection pooling in addition to the pooling that Sequel uses. You should make sure that you don't set the connection pool size to more than 8 for a Sequel::DataObjects::Database object, or hack DataObjects (or Extlib) to use a pool size at least as large as the pool size being used by Sequel.

Constants

DISCONNECT_ERROR_RE
DatasetClass

Public Instance Methods

connect(server) click to toggle source

Setup a DataObjects::Connection to the database.

# File lib/sequel/adapters/do.rb, line 36
def connect(server)
  setup_connection(::DataObjects::Connection.new(uri(server_opts(server))))
end
disconnect_connection(conn) click to toggle source
# File lib/sequel/adapters/do.rb, line 40
def disconnect_connection(conn)
  conn.dispose
end
execute(sql, opts=OPTS) { |res| ... } click to toggle source

Execute the given SQL. If a block is given, the DataObjects::Reader created is yielded to it. A block should not be provided unless a a SELECT statement is being used (or something else that returns rows). Otherwise, the return value is the insert id if opts is :insert, or the number of affected rows, otherwise.

# File lib/sequel/adapters/do.rb, line 49
def execute(sql, opts=OPTS)
  synchronize(opts[:server]) do |conn|
    begin
      command = conn.create_command(sql)
      res = log_yield(sql){block_given? ? command.execute_reader : command.execute_non_query}
    rescue ::DataObjects::Error => e
      raise_error(e)
    end
    if block_given?
      begin
        yield(res)
      ensure
       res.close if res
      end
    elsif opts[:type] == :insert
      res.insert_id
    else
      res.affected_rows
    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/do.rb, line 73
def execute_dui(sql, opts=OPTS)
  execute(sql, opts)
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/do.rb, line 79
def execute_insert(sql, opts=OPTS)
  execute(sql, opts.merge(:type=>:insert))
end
subadapter() click to toggle source

Return the subadapter type for this database, i.e. sqlite3 for do:sqlite3::memory:.

# File lib/sequel/adapters/do.rb, line 85
def subadapter
  uri.split(":").first
end
uri(opts=OPTS) click to toggle source

Return the DataObjects URI for the Sequel URI, removing the do: prefix.

# File lib/sequel/adapters/do.rb, line 91
def uri(opts=OPTS)
  opts = @opts.merge(opts)
  (opts[:uri] || opts[:url]).sub(/\Ado:/, '')
end

Private Instance Methods

adapter_initialize() click to toggle source

Call the DATABASE_SETUP proc directly after initialization, so the object always uses subadapter specific code. Also, raise an error immediately if the connection doesn't have a uri, since DataObjects requires one.

# File lib/sequel/adapters/do.rb, line 102
def adapter_initialize
  raise(Error, "No connection string specified") unless uri
  if prok = Sequel::Database.load_adapter(subadapter.to_sym, :map=>DATABASE_SETUP, :subdir=>'do')
    prok.call(self)
  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/do.rb, line 111
def connection_execute_method
  :execute_non_query
end
database_error_classes() click to toggle source

dataobjects uses the DataObjects::Error class as the main error class.

# File lib/sequel/adapters/do.rb, line 116
def database_error_classes
  [::DataObjects::Error]
end
disconnect_error?(e, opts) click to toggle source

Recognize DataObjects::ConnectionError instances as disconnect errors.

Calls superclass method Sequel::Database#disconnect_error?
# File lib/sequel/adapters/do.rb, line 121
def disconnect_error?(e, opts)
  super || (e.is_a?(::DataObjects::Error) && (e.is_a?(::DataObjects::ConnectionError) || e.message =~ DISCONNECT_ERROR_RE))
end
log_connection_execute(conn, sql) click to toggle source

Execute SQL on the connection by creating a command first

# File lib/sequel/adapters/do.rb, line 126
def log_connection_execute(conn, sql)
  log_yield(sql){conn.create_command(sql).execute_non_query}
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/do.rb, line 132
def setup_connection(conn)
  conn
end