class Sequel::Amalgalite::Database
amalgalite driver.
Database class for SQLite databases used with Sequel and the
def self.uri_to_options(uri) # :nodoc:
path, and 3 preceding slashes specify an absolute path.
Mimic the file:// uri, by having 2 preceding slashes specify a relative
def self.uri_to_options(uri) # :nodoc: { :database => (uri.host.nil? && uri.path == '/') ? nil : "#{uri.host}#{uri.path}" } end
def _execute(sql, opts)
Yield an available connection. Rescue
def _execute(sql, opts) begin synchronize(opts[:server]){|conn| yield conn} rescue ::Amalgalite::Error, ::Amalgalite::SQLite3::Error => e raise_error(e) end end
def connect(server)
name), and :timeout, to specify how long to wait for the database to
the only options available are :database (to specify the database
Connect to the database. Since SQLite is a file based database,
def connect(server) opts = server_opts(server) opts[:database] = ':memory:' if blank_object?(opts[:database]) db = ::Amalgalite::Database.new(opts[:database]) db.busy_handler(::Amalgalite::BusyTimeout.new(opts.fetch(:timeout, 5000)/50, 50)) db.type_map = SequelTypeMap.new(self) connection_pragmas.each{|s| log_yield(s){db.execute_batch(s)}} db end
def connection_pool_default_options
Also, force the max connections to 1 if a memory database is being
The Amagalite adapter does not need the pool to convert exceptions.
def connection_pool_default_options o = super.dup # Default to only a single connection if a memory database is used, # because otherwise each connection will get a separate database o[:max_connections] = 1 if @opts[:database] == ':memory:' || blank_object?(@opts[:database]) o end
def database_error_classes
def database_error_classes [::Amalgalite::Error, ::Amalgalite::SQLite3::Error] end
def database_type
def database_type :sqlite end
def disconnect_connection(c)
def disconnect_connection(c) c.close end
def execute(sql, opts={})
def execute(sql, opts={}) _execute(sql, opts) do |conn| begin yield(stmt = log_yield(sql){conn.prepare(sql)}) ensure stmt.close if stmt end end end
def execute_ddl(sql, opts={})
def execute_ddl(sql, opts={}) _execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}} nil end
def execute_dui(sql, opts={})
def execute_dui(sql, opts={}) _execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}; conn.row_changes} end
def execute_insert(sql, opts={})
def execute_insert(sql, opts={}) _execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}; conn.last_insert_rowid} end
def single_value(sql, opts={})
def single_value(sql, opts={}) _execute(sql, opts){|conn| log_yield(sql){conn.first_value_from(sql)}} end