Class: ClickhouseRuby::ActiveRecord::SchemaCreation
- Inherits:
-
Object
- Object
- ClickhouseRuby::ActiveRecord::SchemaCreation
- Defined in:
- lib/clickhouse_ruby/active_record/schema_statements.rb
Overview
Schema creation for ClickHouse DDL statements
Instance Method Summary collapse
-
#accept(table_definition) ⇒ String
Generate CREATE TABLE SQL from a TableDefinition.
-
#initialize(adapter) ⇒ SchemaCreation
constructor
A new instance of SchemaCreation.
Constructor Details
#initialize(adapter) ⇒ SchemaCreation
Returns a new instance of SchemaCreation.
600 601 602 |
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 600 def initialize(adapter) @adapter = adapter end |
Instance Method Details
#accept(table_definition) ⇒ String
Generate CREATE TABLE SQL from a TableDefinition
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
# File 'lib/clickhouse_ruby/active_record/schema_statements.rb', line 608 def accept(table_definition) columns_sql = table_definition.columns.map do |col| column_sql(col) end.join(",\n ") engine = table_definition.[:engine] || 'MergeTree' order_by = table_definition.[:order_by] partition_by = table_definition.[:partition_by] primary_key = table_definition.[:primary_key] settings = table_definition.[:settings] sql = "CREATE TABLE #{@adapter.quote_table_name(table_definition.name)} (\n #{columns_sql}\n)" sql += "\nENGINE = #{engine}" sql += "\nORDER BY (#{order_by})" if order_by sql += "\nPARTITION BY #{partition_by}" if partition_by sql += "\nPRIMARY KEY (#{primary_key})" if primary_key sql += "\nSETTINGS #{settings}" if settings sql end |