module ActiveRecord::ConnectionAdapters::CockroachDB::PostgreSQLColumnMonkeyPatch
Attributes
geographic[R]
geographic?[R]
geometric_type[R]
has_m[R]
has_m?[R]
has_z[R]
has_z?[R]
srid[R]
Public Class Methods
new(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, serial: nil, spatial: nil)
click to toggle source
most functions taken from activerecord-postgis-adapter spatial_column github.com/rgeo/activerecord-postgis-adapter/blob/master/lib/active_record/connection_adapters/postgis/spatial_column.rb
Calls superclass method
# File lib/active_record/connection_adapters/cockroachdb/column.rb, line 7 def initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, serial: nil, spatial: nil) @sql_type_metadata = sql_type_metadata @geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i) if spatial # This case comes from an entry in the geometry_columns table set_geometric_type_from_name(spatial[:type]) @srid = spatial[:srid].to_i @has_z = !!spatial[:has_z] @has_m = !!spatial[:has_m] elsif @geographic # Geographic type information is embedded in the SQL type @srid = 4326 @has_z = @has_m = false build_from_sql_type(sql_type_metadata.sql_type) elsif sql_type =~ /geography|geometry|point|linestring|polygon/i build_from_sql_type(sql_type_metadata.sql_type) elsif sql_type_metadata.sql_type =~ /geography|geometry|point|linestring|polygon/i # A geometry column with no geometry_columns entry. # @geometric_type = geo_type_from_sql_type(sql_type) build_from_sql_type(sql_type_metadata.sql_type) end super(name, default, sql_type_metadata, null, default_function, collation: collation, comment: comment, serial: serial) if spatial? && @srid @limit = { srid: @srid, type: to_type_name(geometric_type) } @limit[:has_z] = true if @has_z @limit[:has_m] = true if @has_m @limit[:geographic] = true if @geographic end end
Public Instance Methods
limit()
click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/cockroachdb/column.rb, line 51 def limit spatial? ? @limit : super end
serial?()
click to toggle source
# File lib/active_record/connection_adapters/cockroachdb/column.rb, line 59 def serial? default_function == 'unique_rowid()' end
spatial?()
click to toggle source
# File lib/active_record/connection_adapters/cockroachdb/column.rb, line 55 def spatial? %i[geometry geography].include?(@sql_type_metadata.type) end
Private Instance Methods
build_from_sql_type(sql_type)
click to toggle source
# File lib/active_record/connection_adapters/cockroachdb/column.rb, line 69 def build_from_sql_type(sql_type) geo_type, @srid, @has_z, @has_m = OID::Spatial.parse_sql_type(sql_type) set_geometric_type_from_name(geo_type) end
set_geometric_type_from_name(name)
click to toggle source
# File lib/active_record/connection_adapters/cockroachdb/column.rb, line 65 def set_geometric_type_from_name(name) @geometric_type = RGeo::ActiveRecord.geometric_type_from_name(name) || RGeo::Feature::Geometry end
to_type_name(geometric_type)
click to toggle source
# File lib/active_record/connection_adapters/cockroachdb/column.rb, line 74 def to_type_name(geometric_type) name = geometric_type.type_name.underscore case name when 'point' 'st_point' when 'polygon' 'st_polygon' else name end end