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
89 def connect(server)
90   opts = server_opts(server)
91   opts[:database] = ':memory:' if blank_object?(opts[:database])
92   db = ::Amalgalite::Database.new(opts[:database])
93   db.busy_handler(::Amalgalite::BusyTimeout.new(opts.fetch(:timeout, 5000)/50, 50))
94   db.type_map = SequelTypeMap.new(self)
95   connection_pragmas.each{|s| log_connection_yield(s, db){db.execute_batch(s)}}
96   db
97 end
database_type() click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
 99 def database_type
100   :sqlite
101 end
execute(sql, opts=OPTS) { |stmt = log_connection_yield(sql, conn){prepare}| ... } click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
116 def execute(sql, opts=OPTS)
117   _execute(sql, opts) do |conn|
118     begin
119       yield(stmt = log_connection_yield(sql, conn){conn.prepare(sql)})
120     ensure
121       stmt.close if stmt
122     end
123   end
124 end
execute_ddl(sql, opts=OPTS) click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
103 def execute_ddl(sql, opts=OPTS)
104   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}}
105   nil
106 end
execute_dui(sql, opts=OPTS) click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
108 def execute_dui(sql, opts=OPTS)
109   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.row_changes}
110 end
execute_insert(sql, opts=OPTS) click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
112 def execute_insert(sql, opts=OPTS)
113   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.last_insert_rowid}
114 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
127 def single_value(sql, opts=OPTS)
128   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.first_value_from(sql)}}
129 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
135 def _execute(sql, opts)
136   synchronize(opts[:server]){|conn| yield conn}
137 rescue ::Amalgalite::Error, ::Amalgalite::SQLite3::Error => e
138   raise_error(e)
139 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
144 def connection_pool_default_options
145   o = super.dup
146   # Default to only a single connection if a memory database is used,
147   # because otherwise each connection will get a separate database
148   o[:max_connections] = 1 if @opts[:database] == ':memory:' || blank_object?(@opts[:database])
149   o
150 end
database_error_classes() click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
156 def database_error_classes
157   [::Amalgalite::Error, ::Amalgalite::SQLite3::Error]
158 end
dataset_class_default() click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
152 def dataset_class_default
153   Dataset
154 end