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
74 def connect(server)
75   opts = server_opts(server)
76   opts[:database] = ':memory:' if blank_object?(opts[:database])
77   db = ::Amalgalite::Database.new(opts[:database])
78   db.busy_handler(::Amalgalite::BusyTimeout.new(opts.fetch(:timeout, 5000)/50, 50))
79   db.type_map = SequelTypeMap.new(self)
80   connection_pragmas.each{|s| log_connection_yield(s, db){db.execute_batch(s)}}
81   db
82 end
database_type() click to toggle source
   # File lib/sequel/adapters/amalgalite.rb
84 def database_type
85   :sqlite
86 end
execute(sql, opts=OPTS) { |stmt = log_connection_yield(sql, conn){prepare}| ... } click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
101 def execute(sql, opts=OPTS)
102   _execute(sql, opts) do |conn|
103     begin
104       yield(stmt = log_connection_yield(sql, conn){conn.prepare(sql)})
105     ensure
106       stmt.close if stmt
107     end
108   end
109 end
execute_ddl(sql, opts=OPTS) click to toggle source
   # File lib/sequel/adapters/amalgalite.rb
88 def execute_ddl(sql, opts=OPTS)
89   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}}
90   nil
91 end
execute_dui(sql, opts=OPTS) click to toggle source
   # File lib/sequel/adapters/amalgalite.rb
93 def execute_dui(sql, opts=OPTS)
94   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.row_changes}
95 end
execute_insert(sql, opts=OPTS) click to toggle source
   # File lib/sequel/adapters/amalgalite.rb
97 def execute_insert(sql, opts=OPTS)
98   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.execute_batch(sql)}; conn.last_insert_rowid}
99 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
112 def single_value(sql, opts=OPTS)
113   _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.first_value_from(sql)}}
114 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
120 def _execute(sql, opts)
121   synchronize(opts[:server]){|conn| yield conn}
122 rescue ::Amalgalite::Error, ::Amalgalite::SQLite3::Error => e
123   raise_error(e)
124 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
129 def connection_pool_default_options
130   o = super.dup
131   # Default to only a single connection if a memory database is used,
132   # because otherwise each connection will get a separate database
133   o[:max_connections] = 1 if @opts[:database] == ':memory:' || blank_object?(@opts[:database])
134   o
135 end
database_error_classes() click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
141 def database_error_classes
142   [::Amalgalite::Error, ::Amalgalite::SQLite3::Error]
143 end
dataset_class_default() click to toggle source
    # File lib/sequel/adapters/amalgalite.rb
137 def dataset_class_default
138   Dataset
139 end