class ActiveRecord::ConnectionAdapters::SQLite3Adapter

Parent:
ActiveRecord::ConnectionAdapters::AbstractAdapter
Included modules:
ActiveRecord::ConnectionAdapters::SQLite3::DatabaseStatements

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

Options:

  • :database - Path to the database file.

Constants

ADAPTER_NAME
COLLATE_REGEX
NATIVE_DATABASE_TYPES

Public Class Methods

database_exists?(config) Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 101
def self.database_exists?(config)
  config = config.symbolize_keys
  if config[:database] == ":memory:"
    return true
  else
    database_file = defined?(Rails.root) ? File.expand_path(config[:database], Rails.root) : config[:database]
    File.exist?(database_file)
  end
end
new(connection, logger, connection_options, config) Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 96
def initialize(connection, logger, connection_options, config)
  super(connection, logger, config)
  configure_connection
end

Public Instance Methods

active?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 154
def active?
  [email protected]?
end
allowed_index_name_length() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 177
def allowed_index_name_length
  index_name_length - 2
end

Returns 62. SQLite supports index names up to 64 characters. The rest is used by Rails internally to perform temporary rename operations

disconnect!() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 165
def disconnect!
  super
  @connection.close rescue nil
end

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

encoding() Show source
# 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, eg: 'UTF-8'

explain(arel, binds = []) Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 217
def explain(arel, binds = [])
  sql = "EXPLAIN QUERY PLAN #{to_sql(arel, binds)}"
  SQLite3::ExplainPrettyPrinter.new.pp(exec_query(sql, "EXPLAIN", []))
end
foreign_keys(table_name) Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 304
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
reconnect!() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 158
def reconnect!
  super
  connect if @connection.closed?
end
rename_table(table_name, new_name) Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 238
def rename_table(table_name, new_name)
  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')
requires_reloading?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 127
def requires_reloading?
  true
end
supports_datetime_with_precision?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 139
def supports_datetime_with_precision?
  true
end
supports_ddl_transactions?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 111
def supports_ddl_transactions?
  true
end
supports_explain?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 190
def supports_explain?
  true
end
supports_expression_index?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 123
def supports_expression_index?
  database_version >= "3.9.0"
end
supports_foreign_keys?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 131
def supports_foreign_keys?
  true
end
supports_index_sort_order?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 170
def supports_index_sort_order?
  true
end
supports_insert_conflict_target?()
supports_insert_on_conflict?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 147
def supports_insert_on_conflict?
  database_version >= "3.24.0"
end
supports_insert_on_duplicate_skip?()
supports_insert_on_duplicate_update?()
supports_json?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 143
def supports_json?
  true
end
supports_lazy_transactions?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 194
def supports_lazy_transactions?
  true
end
supports_partial_index?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 119
def supports_partial_index?
  true
end
supports_savepoints?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 115
def supports_savepoints?
  true
end
supports_views?() Show source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 135
def supports_views?
  true
end

© 2004–2019 David Heinemeier Hansson
Licensed under the MIT License.