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

ADAPTER_NAME =
"Mysql2Rgeo"
SPATIAL_COLUMN_OPTIONS =
{
  geometry:            {},
  geometrycollection:  {},
  linestring:          {},
  multilinestring:     {},
  multipoint:          {},
  multipolygon:        {},
  spatial:             { type: "geometry" },
  point:               {},
  polygon:             {}
}.freeze
DEFAULT_SRID =
0
TYPE_MAP =
Type::TypeMap.new.tap { |m| initialize_type_map(m) }
TYPE_MAP_WITH_BOOLEAN =
Type::TypeMap.new(TYPE_MAP).tap do |m|
  m.register_type %r(^tinyint\(1\))i, Type::Boolean.new
end

Class Method Summary collapse

Instance Method Summary collapse

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

#indexes, #type_to_sql

Constructor Details

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

Returns a new instance of Mysql2RgeoAdapter.



69
70
71
72
73
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 69

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

  @visitor = Arel::Visitors::Mysql2Rgeo.new(self)
end

Class Method Details

.spatial_column_options(key) ⇒ Object



75
76
77
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 75

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

Instance Method Details

#default_sridObject



79
80
81
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 79

def default_srid
  DEFAULT_SRID
end

#native_database_typesObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 83

def native_database_types
  # Add spatial types
  # Reference: https://dev.mysql.com/doc/refman/5.6/en/spatial-type-overview.html
  super.merge(
    geometry:            { name: "geometry" },
    geometrycollection:  { name: "geometrycollection" },
    linestring:          { name: "linestring" },
    multi_line_string:   { name: "multilinestring" },
    multi_point:         { name: "multipoint" },
    multi_polygon:       { name: "multipolygon" },
    spatial:             { name: "geometry" },
    point:               { name: "point" },
    polygon:             { name: "polygon" }
  )
end

#quote(value) ⇒ Object



131
132
133
134
135
136
137
138
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 131

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

#supports_spatial?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 127

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