Class: ClickhouseRuby::ActiveRecord::TableDefinition
- Inherits:
-
Object
- Object
- ClickhouseRuby::ActiveRecord::TableDefinition
- Defined in:
- lib/clickhouse_ruby/active_record/schema_statements.rb
Overview
Table definition for ClickHouse CREATE TABLE statements
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#column(name, type, **options) ⇒ self
Add a column to the table definition.
-
#initialize(adapter, name, **options) ⇒ TableDefinition
constructor
A new instance of TableDefinition.
-
#primary_key(name, type = :primary_key, **options) ⇒ Object
Primary key column (UInt64 for ClickHouse).
-
#timestamps(**options) ⇒ Object
Timestamps (created_at, updated_at).
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, **) @adapter = adapter @name = name @columns = [] @options = end |
Instance Attribute Details
#columns ⇒ Object (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 |
#name ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
559 560 561 |
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 559 def @options end |
Instance Method Details
#column(name, type, **options) ⇒ self
Add a column to the table definition
574 575 576 577 |
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 574 def column(name, type, **) @columns << { name: name.to_s, type: type, 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, **) column(name, type, **) 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 (**) column(:created_at, :datetime, **) column(:updated_at, :datetime, **) end |