Class: ClickHouse::Definition::ColumnSet

Inherits:
Object
  • Object
show all
Defined in:
lib/click_house/definition/column_set.rb

Constant Summary collapse

TYPES =
ClickHouse.type_names(nullable: false).map { |s| s.sub('%s', "'%s'") }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ ColumnSet

Returns a new instance of ColumnSet.

Yields:

  • (_self)

Yield Parameters:


35
36
37
# File 'lib/click_house/definition/column_set.rb', line 35

def initialize
  yield(self) if block_given?
end

Class Method Details

.method_name_for_type(type) ⇒ Object


11
12
13
# File 'lib/click_house/definition/column_set.rb', line 11

def method_name_for_type(type)
  type.sub(/\(.+/, '')
end

Instance Method Details

#columnsObject


39
40
41
# File 'lib/click_house/definition/column_set.rb', line 39

def columns
  @columns ||= []
end

#nested(name, &block) ⇒ Object Also known as: Nested

Examples:

t.Nested :json do |n|
  n.UInt8 :city_id
end

53
54
55
# File 'lib/click_house/definition/column_set.rb', line 53

def nested(name, &block)
  columns << "#{name} Nested #{ColumnSet.new(&block)}"
end

#push(sql) ⇒ Object Also known as: <<


59
60
61
# File 'lib/click_house/definition/column_set.rb', line 59

def push(sql)
  columns << sql
end

#to_sObject


43
44
45
46
47
# File 'lib/click_house/definition/column_set.rb', line 43

def to_s
  <<~SQL
    ( #{columns.map(&:to_s).join(', ')} )
  SQL
end