Module: ClickhouseRuby::Generators::TypeMapper

Defined in:
lib/clickhouse_ruby/active_record/generators/migration_generator.rb

Overview

Maps Rails types to ClickHouse types

Constant Summary collapse

TYPE_MAP =

Type mapping from Rails types to ClickHouse types

{
  primary_key: "UInt64",
  bigint: "Int64",
  time: "DateTime",
  date: "Date",
  binary: "String",
  boolean: "UInt8",
  uuid: "UUID",
  json: "String",
}.freeze
INTEGER_SIZES =

Integer size mapping

{
  1 => "Int8",
  2 => "Int16",
}.freeze

Class Method Summary collapse

Class Method Details

.to_clickhouse(type, options = {}) ⇒ String

Convert a Rails type to ClickHouse type

Parameters:

  • type (String, Symbol)

    the Rails type

  • options (Hash) (defaults to: {})

    type options

Returns:

  • (String)

    the ClickHouse type



243
244
245
246
247
248
249
250
251
# File 'lib/clickhouse_ruby/active_record/generators/migration_generator.rb', line 243

def to_clickhouse(type, options = {})
  type_sym = type.to_sym

  # Check simple type map first
  return TYPE_MAP[type_sym] if TYPE_MAP.key?(type_sym)

  # Handle complex types
  complex_type(type_sym, options) || type.to_s
end