class ActiveRecord::ConnectionAdapters::BigQueryAdapter
Adapter in the active record namespace
Constants
- ADAPTER_NAME
- ERR_DUPLICATE_KEY_VALUE
- ERR_QUERY_TIMED_OUT
- ERR_QUERY_TIMED_OUT_MESSAGE
Attributes
The object that stores the information that is fetched from the DBMS when a connection is first established.
Public Class Methods
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 48 def initialize(connection, logger, config, database_metadata) super(connection, logger, config) @database_metadata = database_metadata end
Public Instance Methods
Checks whether the connection to the database is still active. This includes checking whether the database is actually capable of responding, i.e. whether the connection isn't stale.
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 63 def active? @connection.run('SELECT TRUE AS active') end
Returns the human-readable name of the adapter.
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 54 def adapter_name ADAPTER_NAME end
Disconnects from the database if already connected. Otherwise, this method does nothing.
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 78 def disconnect! false end
Disconnects from the database if already connected, and establishes a new connection with the database.
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 69 def reconnect! disconnect! @connection = Base.big_query_connection(@config) super end
Protected Instance Methods
Using a BindVisitor so that the SQL string gets substituted before it is sent to the DBMS (to attempt to get as much coverage as possible for DBMSs we don't support).
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 113 def arel_visitor BindSubstitution.new(self) end
Build the type map for ActiveRecord
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 85 def initialize_type_map(map) super end
Explicitly turning off prepared_statements
in the null adapter because there isn't really a standard on which substitution character to use.
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 119 def prepared_statements false end
Turning off support for migrations because there is no information to go off of for what syntax the DBMS will expect.
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 125 def supports_migrations? false end
Translate an exception from the native DBMS to something usable by ActiveRecord
.
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 91 def translate_exception(exception, message) error_number = exception.message[/^\d+/].to_i if error_number == ERR_DUPLICATE_KEY_VALUE ActiveRecord::RecordNotUnique.new(message, exception) # rubocop:disable Metrics/LineLength elsif error_number == ERR_QUERY_TIMED_OUT || exception.message =~ ERR_QUERY_TIMED_OUT_MESSAGE ::BigQueryAdapter::QueryTimeoutError.new(message, exception) # rubocop:enable Metrics/LineLength else super end end
Private Instance Methods
Can't use the built-in ActiveRecord
map#alias_type because it doesn't work with non-string keys, and in our case the keys are (almost) all numeric
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 134 def alias_type(map, new_type, old_type) map.register_type(new_type) do |_, *args| map.lookup(old_type, *args) end end