Class: ClickhouseRuby::Types::UUID

Inherits:
Base
  • Object
show all
Defined in:
lib/clickhouse_ruby/types/uuid.rb

Overview

Type handler for ClickHouse UUID type

UUIDs are stored as 16-byte values but represented as strings in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Constant Summary collapse

UUID_PATTERN =

UUID regex pattern

/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#==, #hash, #initialize, #nullable?, #to_s

Constructor Details

This class inherits a constructor from ClickhouseRuby::Types::Base

Instance Method Details

#cast(value) ⇒ String?

Converts a Ruby value to a UUID string

Parameters:

  • value (Object)

    the value to convert

Returns:

  • (String, nil)

    the UUID string

Raises:



19
20
21
22
23
24
25
# File 'lib/clickhouse_ruby/types/uuid.rb', line 19

def cast(value)
  return nil if value.nil?

  str = normalize_uuid(value)
  validate_uuid!(str, value)
  str
end

#deserialize(value) ⇒ String?

Converts a value from ClickHouse to a UUID string

Parameters:

  • value (Object)

    the value from ClickHouse

Returns:

  • (String, nil)

    the UUID string



31
32
33
34
35
# File 'lib/clickhouse_ruby/types/uuid.rb', line 31

def deserialize(value)
  return nil if value.nil?

  normalize_uuid(value)
end

#serialize(value) ⇒ String

Converts a UUID to SQL literal

Parameters:

  • value (String, nil)

    the UUID value

Returns:

  • (String)

    the SQL literal



41
42
43
44
45
# File 'lib/clickhouse_ruby/types/uuid.rb', line 41

def serialize(value)
  return 'NULL' if value.nil?

  "'#{normalize_uuid(value)}'"
end