The SQLite3 adapter works with the sqlite3-ruby drivers (available as gem from rubygems.org/gems/sqlite3).

Options:

  • :database - Path to the database file.

Methods

Included Modules

Constants

ADAPTER_NAME = "SQLite"
COLLATE_REGEX = /.*\"(\w+)\".*collate\s+\"(\w+)\".*/i.freeze
NATIVE_DATABASE_TYPES = { primary_key: "integer PRIMARY KEY AUTOINCREMENT NOT NULL", string: { name: "varchar" }, text: { name: "text" }, integer: { name: "integer" }, float: { name: "float" }, decimal: { name: "decimal" }, datetime: { name: "datetime" }, time: { name: "time" }, date: { name: "date" }, binary: { name: "blob" }, boolean: { name: "boolean" }, json: { name: "json" }, }

Class Public methods

database_exists?(config)

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 91
      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
🔎 See on GitHub

new(connection, logger, connection_options, config)

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 86
      def initialize(connection, logger, connection_options, config)
        super(connection, logger, config)
        configure_connection
      end
🔎 See on GitHub

Instance Public methods

active?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 156
      def active?
        !@connection.closed?
      end
🔎 See on GitHub

disconnect!()

Disconnects from the database if already connected. Otherwise, this method does nothing.

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 167
      def disconnect!
        super
        @connection.close rescue nil
      end
🔎 See on GitHub

encoding()

Returns the current database encoding format as a string, eg: 'UTF-8'

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 181
      def encoding
        @connection.encoding.to_s
      end
🔎 See on GitHub

foreign_keys(table_name)

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 291
      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
🔎 See on GitHub

reconnect!()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 160
      def reconnect!
        super
        connect if @connection.closed?
      end
🔎 See on GitHub

rename_table(table_name, new_name)

Renames a table.

Example:

rename_table('octopuses', 'octopi')
📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 228
      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
🔎 See on GitHub

requires_reloading?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 121
      def requires_reloading?
        true
      end
🔎 See on GitHub

supports_check_constraints?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 129
      def supports_check_constraints?
        true
      end
🔎 See on GitHub

supports_common_table_expressions?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 145
      def supports_common_table_expressions?
        database_version >= "3.8.3"
      end
🔎 See on GitHub

supports_datetime_with_precision?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 137
      def supports_datetime_with_precision?
        true
      end
🔎 See on GitHub

supports_ddl_transactions?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 101
      def supports_ddl_transactions?
        true
      end
🔎 See on GitHub

supports_explain?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 185
      def supports_explain?
        true
      end
🔎 See on GitHub

supports_expression_index?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 117
      def supports_expression_index?
        database_version >= "3.9.0"
      end
🔎 See on GitHub

supports_foreign_keys?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 125
      def supports_foreign_keys?
        true
      end
🔎 See on GitHub

supports_index_sort_order?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 172
      def supports_index_sort_order?
        true
      end
🔎 See on GitHub

supports_insert_conflict_target?()

supports_insert_on_conflict?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 149
      def supports_insert_on_conflict?
        database_version >= "3.24.0"
      end
🔎 See on GitHub

supports_insert_on_duplicate_skip?()

supports_insert_on_duplicate_update?()

supports_json?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 141
      def supports_json?
        true
      end
🔎 See on GitHub

supports_lazy_transactions?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 189
      def supports_lazy_transactions?
        true
      end
🔎 See on GitHub

supports_partial_index?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 113
      def supports_partial_index?
        true
      end
🔎 See on GitHub

supports_savepoints?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 105
      def supports_savepoints?
        true
      end
🔎 See on GitHub

supports_transaction_isolation?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 109
      def supports_transaction_isolation?
        true
      end
🔎 See on GitHub

supports_views?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 133
      def supports_views?
        true
      end
🔎 See on GitHub