class Sequel::Amalgalite::Database
Public Instance Methods
connect(server)
click to toggle source
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).
# File lib/sequel/adapters/amalgalite.rb, line 73 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_connection_yield(s, db){db.execute_batch(s)}} db end
database_type()
click to toggle source
# File lib/sequel/adapters/amalgalite.rb, line 83 def database_type :sqlite end
execute(sql, opts=OPTS) { |stmt = log_connection_yield(sql, conn){prepare}| ... }
click to toggle source
# File lib/sequel/adapters/amalgalite.rb, line 100 def execute(sql, opts=OPTS) _execute(sql, opts) do |conn| begin yield(stmt = log_connection_yield(sql, conn){conn.prepare(sql)}) ensure stmt.close if stmt end end end
execute_ddl(sql, opts=OPTS)
click to toggle source
# File lib/sequel/adapters/amalgalite.rb, line 87 def execute_ddl(sql, opts=OPTS) _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}} nil end
execute_dui(sql, opts=OPTS)
click to toggle source
# File lib/sequel/adapters/amalgalite.rb, line 92 def execute_dui(sql, opts=OPTS) _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.row_changes} end
execute_insert(sql, opts=OPTS)
click to toggle source
# File lib/sequel/adapters/amalgalite.rb, line 96 def execute_insert(sql, opts=OPTS) _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.last_insert_rowid} end
single_value(sql, opts=OPTS)
click to toggle source
Run the given SQL with the given arguments and return the first value of the first row.
# File lib/sequel/adapters/amalgalite.rb, line 111 def single_value(sql, opts=OPTS) _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.first_value_from(sql)}} end
Private Instance Methods
_execute(sql, opts) { |conn| ... }
click to toggle source
Yield an available connection. Rescue any Amalgalite::Errors and turn them into DatabaseErrors.
# File lib/sequel/adapters/amalgalite.rb, line 119 def _execute(sql, opts) synchronize(opts[:server]){|conn| yield conn} rescue ::Amalgalite::Error, ::Amalgalite::SQLite3::Error => e raise_error(e) end
connection_pool_default_options()
click to toggle source
The Amagalite adapter does not need the pool to convert exceptions. Also, force the max connections to 1 if a memory database is being used, as otherwise each connection gets a separate database.
Calls superclass method
Sequel::Database#connection_pool_default_options
# File lib/sequel/adapters/amalgalite.rb, line 128 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
database_error_classes()
click to toggle source
# File lib/sequel/adapters/amalgalite.rb, line 140 def database_error_classes [::Amalgalite::Error, ::Amalgalite::SQLite3::Error] end
dataset_class_default()
click to toggle source
# File lib/sequel/adapters/amalgalite.rb, line 136 def dataset_class_default Dataset end