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

database_metadata[R]

The object that stores the information that is fetched from the DBMS when a connection is first established.

Public Class Methods

new(connection, logger, config, database_metadata) click to toggle source
Calls superclass method
# 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

active?() click to toggle source

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
adapter_name() click to toggle source

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
disconnect!() click to toggle source

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
reconnect!() click to toggle source

Disconnects from the database if already connected, and establishes a new connection with the database.

Calls superclass method
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 69
def reconnect!
  disconnect!
  @connection = Base.big_query_connection(@config)
  super
end
Also aliased as: reset!
reset!()
Alias for: reconnect!

Protected Instance Methods

arel_visitor() click to toggle source

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
initialize_type_map(map) click to toggle source

Build the type map for ActiveRecord

Calls superclass method
# File lib/active_record/connection_adapters/big_query_adapter.rb, line 85
def initialize_type_map(map)
  super
end
prepared_statements() click to toggle source

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
supports_migrations?() click to toggle source

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_exception(exception, message) click to toggle source

Translate an exception from the native DBMS to something usable by ActiveRecord.

Calls superclass method
# 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

alias_type(map, new_type, old_type) click to toggle source

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