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 78 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
Amalgalite is just the SQLite database without a separate SQLite installation.
# File lib/sequel/adapters/amalgalite.rb, line 89 def database_type :sqlite end
Run the given SQL with the given arguments and yield each row.
# File lib/sequel/adapters/amalgalite.rb, line 110 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
Run the given SQL with the given arguments. Returns nil.
# File lib/sequel/adapters/amalgalite.rb, line 94 def execute_ddl(sql, opts=OPTS) _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}} nil end
Run the given SQL with the given arguments and return the number of changed rows.
# File lib/sequel/adapters/amalgalite.rb, line 100 def execute_dui(sql, opts=OPTS) _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.row_changes} end
Run the given SQL with the given arguments and return the last inserted row id.
# File lib/sequel/adapters/amalgalite.rb, line 105 def execute_insert(sql, opts=OPTS) _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.last_insert_rowid} end
Run the given SQL with the given arguments and return the first value of the first row.
# File lib/sequel/adapters/amalgalite.rb, line 121 def single_value(sql, opts=OPTS) _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.first_value_from(sql)}} end