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
115 def connect(server)
116   opts = server_opts(server)
117   opts[:database] = ':memory:' if blank_object?(opts[:database])
118   db = ::Amalgalite::Database.new(opts[:database])
119   db.busy_handler(::Amalgalite::BusyTimeout.new(opts.fetch(:timeout, 5000)/50, 50))
120   db.type_map = SequelTypeMap.new(self)
121   connection_pragmas.each{|s| log_connection_yield(s, db){db.execute_batch(s)}}
122   db
123 end
database_type() click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
125 def database_type
126   :sqlite
127 end
execute(sql, opts=OPTS) { |stmt = log_connection_yield(sql, conn){prepare}| ... } click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
142 def execute(sql, opts=OPTS)
143   _execute(sql, opts) do |conn|
144     begin
145       yield(stmt = log_connection_yield(sql, conn){conn.prepare(sql)})
146     ensure
147       stmt.close if stmt
148     end
149   end
150 end
execute_ddl(sql, opts=OPTS) click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
129 def execute_ddl(sql, opts=OPTS)
130   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}}
131   nil
132 end
execute_dui(sql, opts=OPTS) click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
134 def execute_dui(sql, opts=OPTS)
135   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.row_changes}
136 end
execute_insert(sql, opts=OPTS) click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
138 def execute_insert(sql, opts=OPTS)
139   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.last_insert_rowid}
140 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
153 def single_value(sql, opts=OPTS)
154   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.first_value_from(sql)}}
155 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
161 def _execute(sql, opts)
162   synchronize(opts[:server]){|conn| yield conn}
163 rescue ::Amalgalite::Error, ::Amalgalite::SQLite3::Error => e
164   raise_error(e)
165 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.

    # File lib/sequel/adapters/amalgalite.rb
170 def connection_pool_default_options
171   o = super.dup
172   # Default to only a single connection if a memory database is used,
173   # because otherwise each connection will get a separate database
174   o[:max_connections] = 1 if @opts[:database] == ':memory:' || blank_object?(@opts[:database])
175   o
176 end
database_error_classes() click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
182 def database_error_classes
183   [::Amalgalite::Error, ::Amalgalite::SQLite3::Error]
184 end
dataset_class_default() click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
178 def dataset_class_default
179   Dataset
180 end