Module: ClickhouseRuby::ActiveRecord::SchemaTypeMapper

Defined in:
lib/clickhouse_ruby/active_record/schema_dumper.rb

Overview

Maps SQL types to schema types

Constant Summary collapse

PATTERNS =

Type patterns and their schema types

[
  [/^UInt64$/i, :bigint],
  [/^UInt(8|16|32)$/i, :integer],
  [/^Int(8|16|32)$/i, :integer],
  [/^Int64$/i, :bigint],
  [/^Float(32|64)$/i, :float],
  [/^Decimal/i, :decimal],
  [/^String$/i, :string],
  [/^FixedString/i, :string],
  [/^Date$/i, :date],
  [/^DateTime64/i, :datetime],
  [/^DateTime$/i, :datetime],
  [/^UUID$/i, :uuid],
].freeze

Class Method Summary collapse

Class Method Details

.map(sql_type) ⇒ Symbol

Map a SQL type to schema type

Parameters:

  • sql_type (String)

    the SQL type

Returns:

  • (Symbol)

    the schema type



354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/clickhouse_ruby/active_record/schema_dumper.rb', line 354

def map(sql_type)
  # Handle wrapper types
  return handle_nullable(sql_type) if sql_type.match?(/^Nullable\(/i)
  return handle_low_cardinality(sql_type) if sql_type.match?(/^LowCardinality\(/i)

  # Handle standard types
  PATTERNS.each do |pattern, type|
    return type if sql_type.match?(pattern)
  end

  :string
end