Class: ActiveRecord::ConnectionAdapters::Mysql2RgeoAdapter
Constant Summary
collapse
- SPATIAL_COLUMN_OPTIONS =
{
geometry: {},
geometrycollection: {},
linestring: {},
spatial: { type: "geometry" }.freeze,
point: {},
polygon: {},
multilinestring: {},
multipoint: {},
multipolygon: {},
}.freeze
- DEFAULT_SRID =
0
Class Method Summary
collapse
Instance Method Summary
collapse
#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_name ⇒ Object
56
57
58
|
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 56
def adapter_name
"Mysql2Rgeo".freeze
end
|
#default_srid ⇒ Object
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) indexes = []
current_index = nil
execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", "SCHEMA") do |result|
each_hash(result) do |row|
if current_index != row[:Key_name]
next if row[:Key_name] == "PRIMARY" current_index = row[:Key_name]
mysql_index_type = row[:Index_type].downcase.to_sym
index_type = INDEX_TYPES.include?(mysql_index_type) ? mysql_index_type : nil
index_using = INDEX_USINGS.include?(mysql_index_type) ? mysql_index_type : nil
options = [row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], {}, nil, nil, index_type, index_using, row[:Index_comment].presence]
indexes << if mysql_index_type == :spatial
options.push(true)
Mysql2Rgeo::SpatialIndexDefinition.new(*options)
else
IndexDefinition.new(*options)
end
end
indexes.last.columns << row[:Column_name]
indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part] && mysql_index_type != :spatial
end
end
indexes
end
|
#quote(value, column = nil) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 102
def quote(value, column = nil)
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
68
69
70
|
# File 'lib/active_record/connection_adapters/mysql2rgeo_adapter.rb', line 68
def supports_spatial?
!mariadb? && version >= '5.7.6'
end
|