class ActiveRecord::ConnectionAdapters::Mysql2Rgeo::SpatialColumnInfo
Do spatial sql queries for column info and memoize that info.
Public Class Methods
new(adapter, table_name)
click to toggle source
# File lib/active_record/connection_adapters/mysql2rgeo/spatial_column_info.rb, line 8 def initialize(adapter, table_name) @adapter = adapter @table_name = table_name end
Public Instance Methods
all()
click to toggle source
# File lib/active_record/connection_adapters/mysql2rgeo/spatial_column_info.rb, line 13 def all info = if @adapter.supports_expression_index? @adapter.query( "SELECT column_name, srs_id, column_type FROM INFORMATION_SCHEMA.Columns WHERE table_name='#{@table_name}'" ) else @adapter.query( "SELECT column_name, 0, column_type FROM INFORMATION_SCHEMA.Columns WHERE table_name='#{@table_name}'" ) end result = {} info.each do |row| name = row[0] type = row[2] type.sub!(/m$/, "") result[name] = { name: name, srid: row[1].to_i, type: type, } end result end
get(column_name, type)
click to toggle source
do not query the database for non-spatial columns/tables
# File lib/active_record/connection_adapters/mysql2rgeo/spatial_column_info.rb, line 39 def get(column_name, type) return unless Mysql2RgeoAdapter.spatial_column_options(type.to_sym) @spatial_column_info ||= all @spatial_column_info[column_name] end