Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/click_house/definition/column_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def method_name_for_type(type)
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def #{method_name}(*definition)
name = definition[0]
extentions = []
extensions = []
options = {}
extensions = Array(definition[1..-1]).each do |el|
el.is_a?(Hash) ? options.merge!(el) : extentions.push(el)
Array(definition[1..-1]).each do |el|
el.is_a?(Hash) ? options.merge!(el) : extensions.push(el)
end

columns << Column.new(type: "#{type}", name: name, extensions: extensions, **options)
Expand Down
25 changes: 14 additions & 11 deletions spec/click_house/definition/column_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def squish(string)
t.UInt16 :year_birth, low_cardinality: true
t.UInt16 :year_death, low_cardinality: true, nullable: true, default: 0
t.Float32 :city_id, default: 0, nullable: true
t.DateTime :updated_at, 'UTC', default: 'NOW()'
t.Nested :json do |n|
n.UInt8 :cid, nullable: true
n.Date :created_at, default: 'NOW()'
Expand All @@ -23,24 +24,26 @@ def squish(string)

let(:expectation) do
<<~SQL
(
money Decimal(5, 5),
year_birth LowCardinality(UInt16),
(
money Decimal(5, 5),
year_birth LowCardinality(UInt16),
year_death LowCardinality(Nullable(UInt16)) DEFAULT 0,
city_id Nullable(Float32) DEFAULT 0,
json Nested (
cid Nullable(UInt8) ,
created_at Date DEFAULT NOW(),
city_id Nullable(Float32) DEFAULT 0,
updated_at DateTime('UTC') DEFAULT NOW(),
json Nested (
cid Nullable(UInt8) ,
created_at Date DEFAULT NOW(),
updated_at DateTime('UTC'),
deleted_at DateTime64(6, 'UTC')
),
words Enum('hello' = 1, 'world' = 2),
tags Array(String)
deleted_at DateTime64(6, 'UTC')
),
words Enum('hello' = 1, 'world' = 2),
tags Array(String)
)
SQL
end

it 'works' do
expect(subject.columns).to include(have_attributes default: "NOW()", extensions: ["UTC"], name: :updated_at, type: "DateTime('%s')") # Correctly handles columns with a mix of hash and non-hash arguments
expect(squish(subject.to_s)).to eq(squish(expectation))
end
end
Expand Down