class Dbsketch::Rendering::SQL::ColumnRenderer
Public Class Methods
new(type_renderer: nil, options: {})
click to toggle source
# File lib/dbsketch/rendering/sql/column_renderer.rb, line 16 def initialize type_renderer: nil, options: {} ### Preconditions raise ArgumentError, "options is not a Hash" unless options.is_a? Hash ### @options = { :pretty => false }.merge options @type_renderer = (nil == type_renderer ? TypeRenderer.new : type_renderer) end
Public Instance Methods
create(column)
click to toggle source
# File lib/dbsketch/rendering/sql/column_renderer.rb, line 26 def create column ### Preconditions raise ArgumentError, "column is not a Dbsketch::Model::AbstractColumn" unless column.is_a? Dbsketch::Model::AbstractColumn ### if column.is_a? Dbsketch::Model::ComputedColumn create_computed_column column elsif column.is_a? Dbsketch::Model::Column create_column column else raise ArgumentError, "#{column.class} is an unknown subclass of Dbsketch::Model::AbstractColumn" end end
Private Instance Methods
create_column(column)
click to toggle source
# File lib/dbsketch/rendering/sql/column_renderer.rb, line 52 def create_column column sql = "#{column.name} #{@type_renderer.create column.type}" sql << " identity(1,1)" if column.identity sql << (column.nullable ? " null" : " not null") if nil != column.default sql << " default #{column.default}" end sql << get_semantic(column) sql end
create_computed_column(column)
click to toggle source
# File lib/dbsketch/rendering/sql/column_renderer.rb, line 63 def create_computed_column column sql = "#{column.name} as #{column.query}" sql << " persisted" if column.persisted sql << " not null" if not column.nullable sql << get_semantic(column) sql end
get_semantic(column)
click to toggle source
# File lib/dbsketch/rendering/sql/column_renderer.rb, line 41 def get_semantic column sql = "" if @options[:pretty] and (nil != column.meaning or nil != column.comment) sql << " -- " sql << column.meaning if nil != column.meaning sql << ". " if nil != column.meaning and nil != column.comment sql << column.comment if nil != column.comment end sql end