class ActiveRecord::ConnectionAdapters::SpannerAdapter

Constants

ADAPTER_NAME
NATIVE_DATABASE_TYPES

Public Class Methods

database_exists?(config) click to toggle source

Database

# File lib/active_record/connection_adapters/spanner_adapter.rb, line 91
def self.database_exists? config
  connection = ActiveRecordSpannerAdapter::Connection.new config
  connection.connect!
  true
rescue ActiveRecord::NoDatabaseError
  false
end
new(connection, logger, connection_options, config) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 76
def initialize connection, logger, connection_options, config
  super connection, logger, config
  @connection_options = connection_options
end

Public Instance Methods

active?() click to toggle source

Connection management

# File lib/active_record/connection_adapters/spanner_adapter.rb, line 101
def active?
  @connection.active?
end
arel_visitor() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 177
def arel_visitor
  Arel::Visitors::Spanner.new self
end
current_spanner_transaction() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 119
def current_spanner_transaction
  @connection.current_transaction
end
disconnect!() click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 105
def disconnect!
  super
  @connection.disconnect!
end
max_identifier_length() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 81
def max_identifier_length
  128
end
native_database_types() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 85
def native_database_types
  NATIVE_DATABASE_TYPES
end
next_sequence_value(_sequence_name) click to toggle source

Generate next sequence number for primary key

# File lib/active_record/connection_adapters/spanner_adapter.rb, line 173
def next_sequence_value _sequence_name
  SecureRandom.uuid.gsub("-", "").hex & 0x7FFFFFFFFFFFFFFF
end
prefetch_primary_key?(_table_name = nil) click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 168
def prefetch_primary_key? _table_name = nil
  true
end
reconnect!()
Alias for: reset!
reset!() click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 110
def reset!
  super
  @connection.reset!
end
Also aliased as: reconnect!
supports_bulk_alter?() click to toggle source

Supported features

# File lib/active_record/connection_adapters/spanner_adapter.rb, line 125
def supports_bulk_alter?
  true
end
supports_common_table_expressions?() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 129
def supports_common_table_expressions?
  true
end
supports_explain?() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 133
def supports_explain?
  false
end
supports_foreign_keys?() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 137
def supports_foreign_keys?
  true
end
supports_index_sort_order?() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 141
def supports_index_sort_order?
  true
end
supports_insert_conflict_target?()
supports_insert_on_conflict?() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 145
def supports_insert_on_conflict?
  true
end
supports_insert_on_duplicate_skip?()
supports_insert_on_duplicate_update?()
supports_insert_returning?() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 152
def supports_insert_returning?
  true
end
supports_multi_insert?() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 156
def supports_multi_insert?
  true
end
supports_optimizer_hints?() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 160
def supports_optimizer_hints?
  true
end
supports_primary_key?() click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 164
def supports_primary_key?
  true
end

Private Instance Methods

extract_limit(sql_type) click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 211
def extract_limit sql_type
  value = /\((.*)\)/.match sql_type
  return unless value

  value[1] == "MAX" ? "MAX" : value[1].to_i
end
initialize_type_map(m = type_map) click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 183
def initialize_type_map m = type_map
  m.register_type "BOOL", Type::Boolean.new
  register_class_with_limit(
    m, %r{^BYTES}i, ActiveRecord::Type::Spanner::Bytes
  )
  m.register_type "DATE", Type::Date.new
  m.register_type "FLOAT64", Type::Float.new
  m.register_type "NUMERIC", Type::Decimal.new
  m.register_type "INT64", Type::Integer.new(limit: 8)
  register_class_with_limit m, %r{^STRING}i, Type::String
  m.register_type "TIMESTAMP", ActiveRecord::Type::Spanner::Time.new
  m.register_type "JSON", ActiveRecord::Type::Json.new

  register_array_types m
end
register_array_types(m) click to toggle source
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 199
def register_array_types m
  m.register_type %r{^ARRAY<BOOL>}i, Type::Spanner::Array.new(Type::Boolean.new)
  m.register_type %r{^ARRAY<BYTES\((MAX|d+)\)>}i, Type::Spanner::Array.new(Type::Binary.new)
  m.register_type %r{^ARRAY<DATE>}i, Type::Spanner::Array.new(Type::Date.new)
  m.register_type %r{^ARRAY<FLOAT64>}i, Type::Spanner::Array.new(Type::Float.new)
  m.register_type %r{^ARRAY<NUMERIC>}i, Type::Spanner::Array.new(Type::Decimal.new)
  m.register_type %r{^ARRAY<INT64>}i, Type::Spanner::Array.new(Type::Integer.new(limit: 8))
  m.register_type %r{^ARRAY<STRING\((MAX|d+)\)>}i, Type::Spanner::Array.new(Type::String.new)
  m.register_type %r{^ARRAY<TIMESTAMP>}i, Type::Spanner::Array.new(ActiveRecord::Type::Spanner::Time.new)
  m.register_type %r{^ARRAY<JSON>}i, Type::Spanner::Array.new(ActiveRecord::Type::Json.new)
end
translate_exception(exception, message:, sql:, binds: if exception.is_a? Google::Cloud::FailedPreconditionError) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/spanner_adapter.rb, line 218
def translate_exception exception, message:, sql:, binds:
  if exception.is_a? Google::Cloud::FailedPreconditionError
    case exception.message
    when /.*does not specify a non-null value for these NOT NULL columns.*/,
         /.*must not be NULL.*/
      NotNullViolation.new message, sql: sql, binds: binds
    else
      super
    end
  else
    super
  end