Class: Sequel::Amalgalite::Database

Inherits:
Database
  • Object
show all
Includes:
SQLite::DatabaseMethods
Defined in:
lib/sequel/adapters/amalgalite.rb

Constant Summary

Constants included from SQLite::DatabaseMethods

SQLite::DatabaseMethods::AUTO_VACUUM, SQLite::DatabaseMethods::SYNCHRONOUS, SQLite::DatabaseMethods::TEMP_STORE, SQLite::DatabaseMethods::TRANSACTION_MODE

Instance Attribute Summary

Attributes included from SQLite::DatabaseMethods

#current_timestamp_utc, #integer_booleans, #transaction_mode, #use_timestamp_timezones

Instance Method Summary collapse

Methods included from SQLite::DatabaseMethods

#foreign_key_list, #freeze, #indexes, #set_integer_booleans, #sqlite_version, #support_without_rowid?, #supports_create_table_if_not_exists?, #supports_deferrable_foreign_key_constraints?, #supports_partial_indexes?, #supports_savepoints?, #tables, #use_timestamp_timezones?, #values, #views

Instance Method Details

#connect(server) ⇒ Object

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).



115
116
117
118
119
120
121
122
123
# File 'lib/sequel/adapters/amalgalite.rb', line 115

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 ⇒ Object



125
126
127
# File 'lib/sequel/adapters/amalgalite.rb', line 125

def database_type
  :sqlite
end

#execute(sql, opts = OPTS) ⇒ Object



142
143
144
145
146
147
148
149
150
# File 'lib/sequel/adapters/amalgalite.rb', line 142

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) ⇒ Object



129
130
131
132
# File 'lib/sequel/adapters/amalgalite.rb', line 129

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) ⇒ Object



134
135
136
# File 'lib/sequel/adapters/amalgalite.rb', line 134

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) ⇒ Object



138
139
140
# File 'lib/sequel/adapters/amalgalite.rb', line 138

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) ⇒ Object

Run the given SQL with the given arguments and return the first value of the first row.



153
154
155
# File 'lib/sequel/adapters/amalgalite.rb', line 153

def single_value(sql, opts=OPTS)
  _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.first_value_from(sql)}}
end