Class: ClickhouseRuby::ActiveRecord::TableDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/clickhouse_ruby/active_record/schema_statements.rb

Overview

Table definition for ClickHouse CREATE TABLE statements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter, name, **options) ⇒ TableDefinition

Returns a new instance of TableDefinition.



561
562
563
564
565
566
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 561

def initialize(adapter, name, **options)
  @adapter = adapter
  @name = name
  @columns = []
  @options = options
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



559
560
561
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 559

def columns
  @columns
end

#nameObject (readonly)

Returns the value of attribute name.



559
560
561
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 559

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



559
560
561
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 559

def options
  @options
end

Instance Method Details

#column(name, type, **options) ⇒ self

Add a column to the table definition

Parameters:

  • name (String, Symbol)

    the column name

  • type (Symbol, String)

    the column type

  • options (Hash)

    column options

Returns:

  • (self)


574
575
576
577
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 574

def column(name, type, **options)
  @columns << { name: name.to_s, type: type, options: options }
  self
end

#primary_key(name, type = :primary_key, **options) ⇒ Object

Primary key column (UInt64 for ClickHouse)



587
588
589
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 587

def primary_key(name, type = :primary_key, **options)
  column(name, type, **options)
end

#timestamps(**options) ⇒ Object

Timestamps (created_at, updated_at)



592
593
594
595
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 592

def timestamps(**options)
  column(:created_at, :datetime, **options)
  column(:updated_at, :datetime, **options)
end