class Sequel::Amalgalite::Database

  1. lib/sequel/adapters/amalgalite.rb
Parent: Amalgalite

Database class for SQLite databases used with Sequel and the amalgalite driver.

Public Instance methods

connect (server)

Connect to the database. Since SQLite is a file based database, the only options available are :database (to specify the database name), and :timeout, to specify how long to wait for the database to be available if it is locked, given in milliseconds (default is 5000).

[show source]
# File lib/sequel/adapters/amalgalite.rb, line 76
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
database_type ()

Amalgalite is just the SQLite database without a separate SQLite installation.

[show source]
# File lib/sequel/adapters/amalgalite.rb, line 87
def database_type
  :sqlite
end
execute (sql, opts=OPTS)

Run the given SQL with the given arguments and yield each row.

[show source]
# File lib/sequel/adapters/amalgalite.rb, line 108
def execute(sql, opts=OPTS)
  _execute(sql, opts) do |conn|
    begin
      yield(stmt = log_yield(sql){conn.prepare(sql)})
    ensure
      stmt.close if stmt
    end
  end
end
execute_ddl (sql, opts=OPTS)

Run the given SQL with the given arguments. Returns nil.

[show source]
# File lib/sequel/adapters/amalgalite.rb, line 92
def execute_ddl(sql, opts=OPTS)
  _execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}}
  nil
end
execute_dui (sql, opts=OPTS)

Run the given SQL with the given arguments and return the number of changed rows.

[show source]
# File lib/sequel/adapters/amalgalite.rb, line 98
def execute_dui(sql, opts=OPTS)
  _execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}; conn.row_changes}
end
execute_insert (sql, opts=OPTS)

Run the given SQL with the given arguments and return the last inserted row id.

[show source]
# File lib/sequel/adapters/amalgalite.rb, line 103
def execute_insert(sql, opts=OPTS)
  _execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}; conn.last_insert_rowid}
end
single_value (sql, opts=OPTS)

Run the given SQL with the given arguments and return the first value of the first row.

[show source]
# File lib/sequel/adapters/amalgalite.rb, line 119
def single_value(sql, opts=OPTS)
  _execute(sql, opts){|conn| log_yield(sql){conn.first_value_from(sql)}}
end