Class: ActiveRecord::ConnectionAdapters::Mysql2RgeoAdapter

Inherits:
Mysql2Adapter
  • Object
show all
Includes:
ActiveRecord::ConnectionAdapters::Mysql2Rgeo::SchemaStatements
Defined in:
lib/active_record/connection_adapters/mysql2rgeo_adapter.rb

Constant Summary collapse

SPATIAL_COLUMN_OPTIONS =
{
  geometry: {},
  geometrycollection: {},
  linestring: {},
  multilinestring: {},
  multipoint: {},
  multipolygon: {},
  spatial: { type: "geometry" },
  point: {},
  polygon: {}
}.freeze
DEFAULT_SRID =
0

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveRecord::ConnectionAdapters::Mysql2Rgeo::SchemaStatements

#create_table_definition, #initialize_type_map, #native_database_types, #new_column, #type_to_sql

Constructor Details

#initialize(connection, logger, connection_options, config) ⇒ Mysql2RgeoAdapter

Returns a new instance of Mysql2RgeoAdapter.



49
50
51
52
53
54
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 49

def initialize(connection, logger, connection_options, config)
  super

  @visitor = Arel::Visitors::Mysql2Rgeo.new(self)
  @visitor.extend(DetermineIfPreparableVisitor) if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
end

Class Method Details

.spatial_column_options(key) ⇒ Object



60
61
62
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 60

def self.spatial_column_options(key)
  SPATIAL_COLUMN_OPTIONS[key]
end

Instance Method Details

#adapter_nameObject



56
57
58
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 56

def adapter_name
  "Mysql2Rgeo".freeze
end

#default_sridObject



64
65
66
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 64

def default_srid
  DEFAULT_SRID
end

#indexes(table_name, name = nil) ⇒ Object

Returns an array of indexes for the given table.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 73

def indexes(table_name, name = nil) #:nodoc:
  if name
    ActiveSupport::Deprecation.warn("      Passing name to #indexes is deprecated without replacement.\n    MSG\n  end\n\n  indexes = []\n  current_index = nil\n  execute_and_free(\"SHOW KEYS FROM \#{quote_table_name(table_name)}\", \"SCHEMA\") do |result|\n    each_hash(result) do |row|\n      if current_index != row[:Key_name]\n        next if row[:Key_name] == \"PRIMARY\" # skip the primary key\n        current_index = row[:Key_name]\n\n        mysql_index_type = row[:Index_type].downcase.to_sym\n        index_type = INDEX_TYPES.include?(mysql_index_type) ? mysql_index_type : nil\n        index_using = INDEX_USINGS.include?(mysql_index_type) ? mysql_index_type : nil\n        indexes << IndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], {}, nil, nil, index_type, index_using, row[:Index_comment].presence)\n      end\n\n      indexes.last.columns << row[:Column_name]\n      indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part] && mysql_index_type != :spatial\n    end\n  end\n\n  indexes\nend\n".squish)

#quote(value) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 102

def quote(value)
  if RGeo::Feature::Geometry.check_type(value)
    "ST_GeomFromWKB(0x#{RGeo::WKRep::WKBGenerator.new(hex_format: true, little_endian: true).generate(value)},#{value.srid})"
  else
    super
  end
end

#supports_spatial?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 68

def supports_spatial?
  !mariadb? && version >= "5.7.6"
end