Class/Module Index [+]

Quicksearch

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.

Public Class Methods

new(opts) 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 uri, since DataObjects requires one.

# File lib/sequel/adapters/do.rb, line 45
def initialize(opts)
  super
  raise(Error, "No connection string specified") unless uri
  if prok = DATABASE_SETUP[subadapter.to_sym]
    prok.call(self)
  end
end

Public Instance Methods

connect(server) click to toggle source

Setup a DataObjects::Connection to the database.

# File lib/sequel/adapters/do.rb, line 54
def connect(server)
  setup_connection(::DataObjects::Connection.new(uri(server_opts(server))))
end
dataset(opts = nil) click to toggle source

Return a Sequel::DataObjects::Dataset object for this database.

# File lib/sequel/adapters/do.rb, line 59
def dataset(opts = nil)
  DataObjects::Dataset.new(self, opts)
end
execute(sql, opts={}) 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 68
def execute(sql, 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={}) click to toggle source

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

# File lib/sequel/adapters/do.rb, line 92
def execute_dui(sql, opts={})
  execute(sql, opts)
end
execute_insert(sql, 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 98
def execute_insert(sql, 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 104
def subadapter
  uri.split(":").first
end
uri(opts={}) click to toggle source

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.