class Mystic::SQL::Column
Attributes
constraints[RW]
geom_kind[RW]
geom_srid[RW]
kind[RW]
name[RW]
size[RW]
Public Class Methods
new(opts={})
click to toggle source
# File lib/mystic/sql/column.rb, line 8 def initialize(opts={}) @name = opts.delete(:name).to_s @kind = opts.delete(:kind).to_sym @size = opts.delete(:size).to_s if opts.member? :size @geom_kind = opts.delete(:geom_kind) @geom_srid = opts.delete(:geom_srid).to_i @constraints = opts end
Public Instance Methods
geospatial?()
click to toggle source
# File lib/mystic/sql/column.rb, line 17 def geospatial? @geom_kind && @geom_srid end
to_s()
click to toggle source
# File lib/mystic/sql/column.rb, line 21 def to_s sql = [] sql << name sql << kind.downcase sql << "(#{size})" if size && !size.empty? && !geospatial? sql << "(#{geom_kind}, #{geom_srid})" if geospatial? sql << (constraints[:null] ? "NULL" : "NOT NULL") if constraints.member?(:null) sql << "UNIQUE" if constraints[:unique] sql << "PRIMARY KEY" if constraints[:primary_key] sql << "REFERENCES " + constraints[:references] if constraints.member?(:references) sql << "DEFAULT " + constraints[:default] if constraints.member?(:default) sql << "CHECK(#{constraints[:check]})" if constraints.member?(:check) sql*" " end