Class: Mkxms::Mssql::TableType
- Inherits:
-
Object
- Object
- Mkxms::Mssql::TableType
- Extended by:
- Utils::InitializedAttributes
- 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
-
#name ⇒ Object
Returns the value of attribute name.
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(attrs) ⇒ TableType
constructor
A new instance of TableType.
- #to_sql ⇒ Object
Methods included from Utils::InitializedAttributes
Methods included from Utils::SchemaQualifiedName
Methods included from ExtendedProperties
Methods included from Property::Hosting
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
#name ⇒ Object
Returns the value of attribute name.
146 147 148 |
# File 'lib/mkxms/mssql/table_type_handler.rb', line 146 def name @name end |
#schema ⇒ Object
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_sql ⇒ Object
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 |