The SQLite3
adapter works with the sqlite3-ruby drivers (available as gem from rubygems.org/gems/sqlite3).
Options:
:database
- Path to the database file.
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 92 def self.database_exists?(config) config = config.symbolize_keys if config[:database] == ":memory:" true else database_file = defined?(Rails.root) ? File.expand_path(config[:database], Rails.root) : config[:database] File.exist?(database_file) end end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 86 def initialize(connection, logger, connection_options, config) @memory_database = config[:database] == ":memory:" super(connection, logger, config) configure_connection end
ActiveRecord::ConnectionAdapters::QueryCache::new
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 161 def active? [email protected]? end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 172 def disconnect! super @connection.close rescue nil end
Disconnects from the database if already connected. Otherwise, this method does nothing.
ActiveRecord::ConnectionAdapters::AbstractAdapter#disconnect!
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 186 def encoding @connection.encoding.to_s end
Returns the current database encoding format as a string, e.g. 'UTF-8'
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 308 def foreign_keys(table_name) fk_info = exec_query("PRAGMA foreign_key_list(#{quote(table_name)})", "SCHEMA") fk_info.map do |row| options = { column: row["from"], primary_key: row["to"], on_delete: extract_foreign_key_action(row["on_delete"]), on_update: extract_foreign_key_action(row["on_update"]) } ForeignKeyDefinition.new(table_name, row["table"], options) end end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 165 def reconnect! super connect if @connection.closed? end
ActiveRecord::ConnectionAdapters::AbstractAdapter#reconnect!
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 237 def rename_table(table_name, new_name) schema_cache.clear_data_source_cache!(table_name.to_s) schema_cache.clear_data_source_cache!(new_name.to_s) exec_query "ALTER TABLE #{quote_table_name(table_name)} RENAME TO #{quote_table_name(new_name)}" rename_table_indexes(table_name, new_name) end
Renames a table.
Example:
rename_table('octopuses', 'octopi')
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 122 def requires_reloading? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 130 def supports_check_constraints? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 146 def supports_common_table_expressions? database_version >= "3.8.3" end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 157 def supports_concurrent_connections? !@memory_database end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 138 def supports_datetime_with_precision? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 102 def supports_ddl_transactions? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 190 def supports_explain? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 118 def supports_expression_index? database_version >= "3.9.0" end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 126 def supports_foreign_keys? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 177 def supports_index_sort_order? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 150 def supports_insert_on_conflict? database_version >= "3.24.0" end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 142 def supports_json? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 194 def supports_lazy_transactions? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 114 def supports_partial_index? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 106 def supports_savepoints? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 110 def supports_transaction_isolation? true end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 134 def supports_views? true end
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.