Class: Sequel::Amalgalite::Database
- 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
-
#connect(server) ⇒ Object
Connect to the database.
- #database_type ⇒ Object
- #execute(sql, opts = OPTS) ⇒ Object
- #execute_ddl(sql, opts = OPTS) ⇒ Object
- #execute_dui(sql, opts = OPTS) ⇒ Object
- #execute_insert(sql, opts = OPTS) ⇒ Object
-
#single_value(sql, opts = OPTS) ⇒ Object
Run the given SQL with the given arguments and return the first value of the first row.
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).
89 90 91 92 93 94 95 96 97 |
# File 'lib/sequel/adapters/amalgalite.rb', line 89 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
99 100 101 |
# File 'lib/sequel/adapters/amalgalite.rb', line 99 def database_type :sqlite end |
#execute(sql, opts = OPTS) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/sequel/adapters/amalgalite.rb', line 116 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
103 104 105 106 |
# File 'lib/sequel/adapters/amalgalite.rb', line 103 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
108 109 110 |
# File 'lib/sequel/adapters/amalgalite.rb', line 108 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
112 113 114 |
# File 'lib/sequel/adapters/amalgalite.rb', line 112 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.
127 128 129 |
# File 'lib/sequel/adapters/amalgalite.rb', line 127 def single_value(sql, opts=OPTS) _execute(sql, opts){|conn| log_connection_yield(sql, conn){conn.first_value_from(sql)}} end |