Active Record 抽象适配器¶ ↑
Active Record 支持多种数据库系统。AbstractAdapter 和相关类构成了实现这一点的抽象层。AbstractAdapter 代表了到数据库的连接,并为数据库特定的功能(如建立连接、转义值、为 :offset 和 :limit 选项构建正确的 SQL 片段等)提供了抽象接口。
所有具体的数据库适配器都遵循此类中定义的接口。ActiveRecord::Base.lease_connection 返回一个 AbstractAdapter 对象,您可以使用它。
适配器中的大多数方法在迁移过程中很有用。尤其值得注意的是,SchemaStatements 提供的实例方法非常有用。
- A
- C
- D
- E
- F
- I
- L
- M
- P
- R
- S
-
- savepoint_errors_invalidate_transactions?,
- schema_cache,
- schema_version,
- shard,
- supports_advisory_locks?,
- supports_bulk_alter?,
- supports_check_constraints?,
- supports_comments?,
- supports_comments_in_create?,
- supports_common_table_expressions?,
- supports_concurrent_connections?,
- supports_datetime_with_precision?,
- supports_ddl_transactions?,
- supports_deferrable_constraints?,
- supports_disabling_indexes?,
- supports_exclusion_constraints?,
- supports_explain?,
- supports_expression_index?,
- supports_extensions?,
- supports_foreign_keys?,
- supports_foreign_tables?,
- supports_index_include?,
- supports_index_sort_order?,
- supports_indexes_in_create?,
- supports_insert_conflict_target?,
- supports_insert_on_duplicate_skip?,
- supports_insert_on_duplicate_update?,
- supports_insert_returning?,
- supports_json?,
- supports_lazy_transactions?,
- supports_materialized_views?,
- supports_nulls_not_distinct?,
- supports_optimizer_hints?,
- supports_partial_index?,
- supports_partitioned_indexes?,
- supports_restart_db_transaction?,
- supports_savepoints?,
- supports_transaction_isolation?,
- supports_unique_constraints?,
- supports_validate_constraints?,
- supports_views?,
- supports_virtual_columns?
- T
- U
- V
- ActiveSupport::Callbacks
- ActiveRecord::ConnectionAdapters::DatabaseLimits
- ActiveRecord::ConnectionAdapters::QueryCache
- ActiveRecord::ConnectionAdapters::Savepoints
常量
| ADAPTER_NAME | = | "Abstract" |
| COMMENT_REGEX | = | %r{(?:--.*\n)|/\*(?:[^*]|\*[^/])*\*/} (注释正则表达式) |
| EXTENDED_TYPE_MAPS | = | Concurrent::Map.new |
| SIMPLE_INT | = | /\A\d+\z/ |
| TYPE_MAP | = | Type::TypeMap.new.tap { |m| initialize_type_map(m) } |
Attributes
| [R] | in_use? | |
| [R] | lock | |
| [R] | logger | |
| [R] | owner | |
| [R] | pool | |
| [R] | visitor |
类公共方法
database_exists?(config) 链接
此适配器对应的数据库是否存在?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 403 def self.database_exists?(config) new(config).database_exists? end
dbconsole(config, options = {}) 链接
打开数据库控制台会话。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 128 def self.dbconsole(config, options = {}) raise NotImplementedError.new("#{self.class} should define `dbconsole` that accepts a db config and options to implement connecting to the db console") end
find_cmd_and_exec(commands, *args) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 99 def self.find_cmd_and_exec(commands, *args) # :doc: commands = Array(commands) dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR) unless (ext = RbConfig::CONFIG["EXEEXT"]).empty? commands = commands.map { |cmd| "#{cmd}#{ext}" } end full_path_command = nil found = commands.detect do |cmd| dirs_on_path.detect do |path| full_path_command = File.join(path, cmd) begin stat = File.stat(full_path_command) rescue SystemCallError else stat.file? && stat.executable? end end end if found exec full_path_command, *args else abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.") end end
type_cast_config_to_boolean(config) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 72 def self.type_cast_config_to_boolean(config) if config == "false" false else config end end
type_cast_config_to_integer(config) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 62 def self.type_cast_config_to_integer(config) if config.is_a?(Integer) config elsif SIMPLE_INT.match?(config) config.to_i else config end end
validate_default_timezone(config) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 80 def self.validate_default_timezone(config) case config when nil when "utc", "local" config.to_sym else raise ArgumentError, "default_timezone must be either 'utc' or 'local'" end end
实例公共方法
active?() 链接
检查到数据库的连接是否仍然有效。这包括检查数据库是否确实能够响应,即连接是否不是陈旧的。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 705 def active? end
adapter_name() 链接
返回适配器的人类可读名称。使用混合大小写 - 如果需要,可以始终使用小写。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 398 def adapter_name self.class::ADAPTER_NAME end
check_all_foreign_keys_valid!() 链接
覆盖以检查数据库中的所有外键约束。如果外键约束不满足,适配器应引发 ActiveRecord::StatementInvalid。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 690 def check_all_foreign_keys_valid! end
clear_cache!(new_connection: false) 链接
清除数据库适配器可能进行的任何缓存。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 792 def clear_cache!(new_connection: false) if @statements @lock.synchronize do if new_connection @statements.reset else @statements.clear end end end end
close() 链接
将连接返回给连接池。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 892 def close pool.checkin self end
connect!() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 833 def connect! verify! self end
connected?() 链接
检查是否已建立到数据库的连接。这不包括检查数据库是否真的能够响应,即连接是否是陈旧的。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 698 def connected? !@raw_connection.nil? end
connection_retries() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 221 def connection_retries (@config[:connection_retries] || 1).to_i end
database_exists?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 407 def database_exists? connect! true rescue ActiveRecord::NoDatabaseError false end
default_timezone() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 237 def default_timezone @default_timezone || ActiveRecord.default_timezone end
disable_extension(name, **) 链接
此方法应由支持扩展的适配器实现。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 617 def disable_extension(name, **) end
disable_referential_integrity() 链接
覆盖以在执行 &block 时关闭引用完整性。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 683 def disable_referential_integrity yield end
discard!() 链接
立即忘记此连接曾经存在。与 disconnect! 不同,这不会与服务器通信。
调用此方法后,所有其他方法的行为都将未定义。这会在子进程丢弃属于其父进程的连接之前被内部调用。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 767 def discard! # This should be overridden by concrete adapters. end
disconnect!() 链接
如果已连接,则断开与数据库的连接。否则,此方法不执行任何操作。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 752 def disconnect! @lock.synchronize do clear_cache!(new_connection: true) reset_transaction @raw_connection_dirty = false @connected_since = nil end end
enable_extension(name, **) 链接
此方法应由支持扩展的适配器实现。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 621 def enable_extension(name, **) end
extensions() 链接
扩展列表,由支持它们的适配器填充。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 671 def extensions [] end
index_algorithms() 链接
索引算法列表,由支持它们的适配器填充。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 676 def index_algorithms {} end
lease() 链接
此方法只能在持有连接池的互斥锁时调用。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 289 def lease if in_use? msg = +"Cannot lease connection, " if @owner == ActiveSupport::IsolatedExecutionState.context msg << "it is already leased by the current thread." else msg << "it is already in use by a different thread: #{@owner}. " \ "Current thread: #{ActiveSupport::IsolatedExecutionState.context}." end raise ActiveRecordError, msg end @owner = ActiveSupport::IsolatedExecutionState.context end
max_jitter() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 213 def max_jitter (@config[:pool_jitter] || 0.2).to_f.clamp(MAX_JITTER) end
pool=(value) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 50 def pool=(value) return if value.eql?(@pool) @schema_cache = nil @pool = value end
pool_jitter(duration) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 324 def pool_jitter(duration) duration * (1.0 - @pool_jitter) end
prefetch_primary_key?(table_name = nil) 链接
是否应在插入语句之前从相应的序列中选择主键值?如果为 true,则在每次插入之前调用 next_sequence_value 来设置记录的主键。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 447 def prefetch_primary_key?(table_name = nil) false end
prepared_statements?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 252 def prepared_statements? @prepared_statements && !prepared_statements_disabled_cache.include?(object_id) end
preventing_writes?() 链接
确定当前是否禁止写入。
返回 true 如果连接是副本,或者返回 current_preventing_writes 的值。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 245 def preventing_writes? return true if replica? return false if connection_descriptor.nil? connection_descriptor.current_preventing_writes end
raw_connection() 链接
提供对适配器底层数据库驱动程序的访问。例如,对于 Mysql2Adapter,此方法返回一个 Mysql2::Client 对象;对于 PostgreSQLAdapter,则返回一个 PG::Connection 对象。
当需要调用专有方法(如 PostgreSQL 的 lo_* 方法)时,这非常有用。
Active Record 无法跟踪使用此客户端是否修改了数据库。如果确实如此,通常需要使用 ActiveRecord::Base.clear_query_cache 来使查询缓存失效。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 860 def raw_connection with_raw_connection do |conn| disable_lazy_transactions! @raw_connection_dirty = true conn end end
reconnect!(restore_transactions: false) 链接
如果已连接,则断开与数据库的连接,并与数据库建立新连接。实现者应定义私有方法 reconnect。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 711 def reconnect!(restore_transactions: false) retries_available = connection_retries deadline = retry_deadline && Process.clock_gettime(Process::CLOCK_MONOTONIC) + retry_deadline @lock.synchronize do @allow_preconnect = false reconnect enable_lazy_transactions! @raw_connection_dirty = false @last_activity = @connected_since = Process.clock_gettime(Process::CLOCK_MONOTONIC) @verified = true @allow_preconnect = true reset_transaction(restore: restore_transactions) do clear_cache!(new_connection: true) attempt_configure_connection end rescue => original_exception translated_exception = translate_exception_class(original_exception, nil, nil) retry_deadline_exceeded = deadline && deadline < Process.clock_gettime(Process::CLOCK_MONOTONIC) if !retry_deadline_exceeded && retries_available > 0 retries_available -= 1 if retryable_connection_error?(translated_exception) backoff(connection_retries - retries_available) retry end end @last_activity = nil @verified = false raise translated_exception end end
replica?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 217 def replica? @config[:replica] || false end
requires_reloading?() 链接
在开发模式下,是否需要在请求之间重新加载连接?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 805 def requires_reloading? false end
reset!() 链接
重置此连接的状态,指示 DBMS 清除事务和其他与连接相关的服务器端状态。通常是数据库相关的操作。
如果数据库驱动程序或协议不支持此类功能,实现者可以将此方法别名为 reconnect!。否则,实现者应在重置连接后(并在仍持有 @lock 的情况下)立即调用 super。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 779 def reset! clear_cache!(new_connection: true) reset_transaction attempt_configure_connection end
retry_deadline() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 229 def retry_deadline if @config[:retry_deadline] @config[:retry_deadline].to_f else nil end end
role() 链接
当前连接的角色(例如 :writing)。在非多角色应用程序中,返回 :writing。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 310 def role @pool.role end
savepoint_errors_invalidate_transactions?() 链接
保存点中的 TransactionRollbackErrors 是否会影响父事务?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 431 def savepoint_errors_invalidate_transactions? false end
schema_cache() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 320 def schema_cache @pool.schema_cache || (@schema_cache ||= BoundSchemaReflection.for_lone_connection(@pool.schema_reflection, self)) end
schema_version() 链接
返回数据库中当前可用的模式的版本标识符。这通常等于已执行的最高编号迁移的数量,或者在没有模式信息/数据库为空时为 0。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 927 def schema_version pool.migration_context.current_version end
shard() 链接
当前连接的分片(例如 :default)。在非分片应用程序中,返回 :default。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 316 def shard @pool.shard end
supports_advisory_locks?() 链接
此适配器是否支持应用程序强制执行的咨询锁定?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 440 def supports_advisory_locks? false end
supports_bulk_alter?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 420 def supports_bulk_alter? false end
supports_check_constraints?() 链接
此适配器是否支持创建检查约束?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 512 def supports_check_constraints? false end
supports_comments?() 链接
此适配器是否支持数据库对象(表、列、索引)的元数据注释?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 547 def supports_comments? false end
supports_comments_in_create?() 链接
是否可以在 create/alter table 语句中指定表、列和索引的注释?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 552 def supports_comments_in_create? false end
supports_common_table_expressions?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 571 def supports_common_table_expressions? false end
supports_concurrent_connections?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 595 def supports_concurrent_connections? true end
supports_datetime_with_precision?() 链接
此适配器是否支持带精度的日期时间?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 537 def supports_datetime_with_precision? false end
supports_ddl_transactions?() 链接
此适配器是否支持事务中的 DDL 回滚?也就是说,CREATE TABLE 或 ALTER TABLE 是否会在事务中回滚?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 416 def supports_ddl_transactions? false end
supports_deferrable_constraints?() 链接
此适配器是否支持创建可延迟约束?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 507 def supports_deferrable_constraints? false end
supports_disabling_indexes?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 603 def supports_disabling_indexes? false end
supports_exclusion_constraints?() 链接
此适配器是否支持创建排除约束?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 517 def supports_exclusion_constraints? false end
supports_explain?() 链接
此适配器是否支持 explain?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 476 def supports_explain? false end
supports_expression_index?() 链接
此适配器是否支持表达式索引?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 471 def supports_expression_index? false end
supports_extensions?() 链接
此适配器是否支持数据库扩展?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 486 def supports_extensions? false end
supports_foreign_keys?() 链接
此适配器是否支持创建外键约束?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 497 def supports_foreign_keys? false end
supports_foreign_tables?() 链接
此适配器是否支持外部/远程表?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 562 def supports_foreign_tables? false end
supports_index_include?() 链接
此适配器是否支持包含非键列?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 466 def supports_index_include? false end
supports_index_sort_order?() 链接
此适配器是否支持索引排序顺序?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 456 def supports_index_sort_order? false end
supports_indexes_in_create?() 链接
此适配器是否支持在创建表的同一语句中创建索引?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 492 def supports_indexes_in_create? false end
supports_insert_conflict_target?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 591 def supports_insert_conflict_target? false end
supports_insert_on_duplicate_skip?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 583 def supports_insert_on_duplicate_skip? false end
supports_insert_on_duplicate_update?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 587 def supports_insert_on_duplicate_update? false end
supports_insert_returning?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 579 def supports_insert_returning? false end
supports_json?() 链接
此适配器是否支持 JSON 数据类型?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 542 def supports_json? false end
supports_lazy_transactions?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 575 def supports_lazy_transactions? false end
supports_materialized_views?() 链接
此适配器是否支持物化视图?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 532 def supports_materialized_views? false end
supports_nulls_not_distinct?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 599 def supports_nulls_not_distinct? false end
supports_optimizer_hints?() 链接
此适配器是否支持优化器提示?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 567 def supports_optimizer_hints? false end
supports_partial_index?() 链接
此适配器是否支持部分索引?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 461 def supports_partial_index? false end
supports_partitioned_indexes?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 451 def supports_partitioned_indexes? false end
supports_restart_db_transaction?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 435 def supports_restart_db_transaction? false end
supports_savepoints?() 链接
此适配器是否支持保存点?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 425 def supports_savepoints? false end
supports_transaction_isolation?() 链接
此适配器是否支持设置事务的隔离级别?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 481 def supports_transaction_isolation? false end
supports_unique_constraints?() 链接
此适配器是否支持创建唯一约束?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 522 def supports_unique_constraints? false end
supports_validate_constraints?() 链接
此适配器是否支持创建无效约束?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 502 def supports_validate_constraints? false end
supports_views?() 链接
此适配器是否支持视图?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 527 def supports_views? false end
supports_virtual_columns?() 链接
此适配器是否支持虚拟列?
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 557 def supports_virtual_columns? false end
throw_away!() 链接
从池中移除连接并断开它。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 786 def throw_away! pool.remove self disconnect! end
unprepared_statement() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 389 def unprepared_statement cache = prepared_statements_disabled_cache.add?(object_id) if @prepared_statements yield ensure cache&.delete(object_id) end
verify!() 链接
检查到数据库的连接是否仍然有效(即不是陈旧的)。这通过调用 active? 在后台完成。如果连接不再有效,则此方法将重新连接到数据库。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 812 def verify! unless active? @lock.synchronize do if @unconfigured_connection @raw_connection = @unconfigured_connection @unconfigured_connection = nil attempt_configure_connection @last_activity = Process.clock_gettime(Process::CLOCK_MONOTONIC) @verified = true @allow_preconnect = true return end reconnect!(restore_transactions: true) end end @last_activity = Process.clock_gettime(Process::CLOCK_MONOTONIC) @verified = true end
verify_timeout() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 225 def verify_timeout (@config[:verify_timeout] || 2).to_i end
实例私有方法
log(sql, name = "SQL", binds = [], type_casted_binds = [], async: false, allow_retry: false, &block) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 1200 def log(sql, name = "SQL", binds = [], type_casted_binds = [], async: false, allow_retry: false, &block) # :doc: instrumenter.instrument( "sql.active_record", sql: sql, name: name, binds: binds, type_casted_binds: type_casted_binds, async: async, allow_retry: allow_retry, connection: self, transaction: current_transaction.user_transaction.presence, affected_rows: 0, row_count: 0, &block ) rescue ActiveRecord::StatementInvalid => ex raise ex.set_query(sql, binds) end