Class: Mkxms::Mssql::TableType

Inherits:
Object
  • Object
show all
Extended by:
Utils::InitializedAttributes
Includes:
ExtendedProperties, Property::Hosting, Property::SchemaScoped, Utils::SchemaQualifiedName
Defined in:
lib/mkxms/mssql/table_type_handler.rb

Defined Under Namespace

Classes: CheckConstraint, Column, ConstraintColumn, KeyConstraint

Constant Summary collapse

SQL_OBJECT_TYPE =
'TYPE'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::InitializedAttributes

attr_init

Methods included from Utils::SchemaQualifiedName

#qualified_name

Methods included from ExtendedProperties

#extended_properties

Methods included from Property::Hosting

#extended_properties_sql

Methods included from Property::SchemaScoped

#property_subject_identifiers, #subitem_extended_properties_sql

Constructor Details

#initialize(attrs) ⇒ TableType

Returns a new instance of TableType.



138
139
140
141
142
143
144
# File 'lib/mkxms/mssql/table_type_handler.rb', line 138

def initialize(attrs)
  a = attrs
  info_ver = (a['eyewkas_ver'] || 1.0).to_f
  raise "mssql-eyewkas table-type ver. 1.1 or compatible required" if info_ver < 1.1 || info_ver >= 2
  @schema = a['schema']
  @name = a['name']
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



146
147
148
# File 'lib/mkxms/mssql/table_type_handler.rb', line 146

def name
  @name
end

#schemaObject

Returns the value of attribute schema.



146
147
148
# File 'lib/mkxms/mssql/table_type_handler.rb', line 146

def schema
  @schema
end

Instance Method Details

#to_sqlObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/mkxms/mssql/table_type_handler.rb', line 149

def to_sql
  [].tap do |lines|
    lines << "CREATE TYPE #{qualified_name} AS TABLE ("
    columns.each_with_index do |col, i|
      lines << "  #{i == 0 ? " " : ","} #{col.name} #{col.type_spec}"
    end
    constraints.each do |c|
      lines << "  , #{c.to_sql}"
    end
    lines << ");"
    lines << extended_properties_sql
    columns.each do |col|
      lines << subitem_extended_properties_sql(col)
    end
  end
end