Class: ActiveRecord::ConnectionAdapters::PostgreSQLColumnDefinition
- Inherits:
-
ColumnDefinition
- Object
- ColumnDefinition
- ActiveRecord::ConnectionAdapters::PostgreSQLColumnDefinition
- Defined in:
- lib/spatial_adapter/postgresql.rb
Instance Attribute Summary (collapse)
-
- (Object) geographic
Returns the value of attribute geographic.
-
- (Object) spatial
readonly
Returns the value of attribute spatial.
-
- (Object) srid
Returns the value of attribute srid.
-
- (Object) table_name
Returns the value of attribute table_name.
-
- (Object) with_m
Returns the value of attribute with_m.
-
- (Object) with_z
Returns the value of attribute with_z.
Instance Method Summary (collapse)
-
- (PostgreSQLColumnDefinition) initialize(base = nil, name = nil, type = nil, limit = nil, default = nil, null = nil, srid = 1, with_z = false, with_m = false, geographic = false)
constructor
A new instance of PostgreSQLColumnDefinition.
- - (Object) sql_type
- - (Object) to_sql
Constructor Details
- (PostgreSQLColumnDefinition) initialize(base = nil, name = nil, type = nil, limit = nil, default = nil, null = nil, srid = 1, with_z = false, with_m = false, geographic = false)
A new instance of PostgreSQLColumnDefinition
279 280 281 282 283 284 285 286 287 |
# File 'lib/spatial_adapter/postgresql.rb', line 279 def initialize(base = nil, name = nil, type=nil, limit=nil, default=nil, null=nil, srid=-1, with_z=false, with_m=false, geographic=false) super(base, name, type, limit, default, null) @table_name = nil @spatial = true @srid = srid @with_z = with_z @with_m = with_m @geographic = geographic end |
Instance Attribute Details
- (Object) geographic
Returns the value of attribute geographic
276 277 278 |
# File 'lib/spatial_adapter/postgresql.rb', line 276 def geographic @geographic end |
- (Object) spatial (readonly)
Returns the value of attribute spatial
277 278 279 |
# File 'lib/spatial_adapter/postgresql.rb', line 277 def spatial @spatial end |
- (Object) srid
Returns the value of attribute srid
276 277 278 |
# File 'lib/spatial_adapter/postgresql.rb', line 276 def srid @srid end |
- (Object) table_name
Returns the value of attribute table_name
275 276 277 |
# File 'lib/spatial_adapter/postgresql.rb', line 275 def table_name @table_name end |
- (Object) with_m
Returns the value of attribute with_m
276 277 278 |
# File 'lib/spatial_adapter/postgresql.rb', line 276 def with_m @with_m end |
- (Object) with_z
Returns the value of attribute with_z
276 277 278 |
# File 'lib/spatial_adapter/postgresql.rb', line 276 def with_z @with_z end |
Instance Method Details
- (Object) sql_type
289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/spatial_adapter/postgresql.rb', line 289 def sql_type if geographic type_sql = base.geometry_data_types[type.to_sym][:name] type_sql += "Z" if with_z type_sql += "M" if with_m # SRID is not yet supported (defaults to 4326) #type_sql += ", #{srid}" if (srid && srid != -1) type_sql = "geography(#{type_sql})" type_sql else super end end |
- (Object) to_sql
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/spatial_adapter/postgresql.rb', line 303 def to_sql if spatial && !geographic type_sql = base.geometry_data_types[type.to_sym][:name] type_sql += "M" if with_m and !with_z if with_m and with_z dimension = 4 elsif with_m or with_z dimension = 3 else dimension = 2 end column_sql = "SELECT AddGeometryColumn('#{table_name}','#{name}',#{srid},'#{type_sql}',#{dimension})" column_sql += ";ALTER TABLE #{table_name} ALTER #{name} SET NOT NULL" if null == false column_sql else super end end |