Class: ClickhouseRuby::Types::UUID
- 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
Instance Method Summary collapse
-
#cast(value) ⇒ String?
Converts a Ruby value to a UUID string.
-
#deserialize(value) ⇒ String?
Converts a value from ClickHouse to a UUID string.
-
#serialize(value) ⇒ String
Converts a UUID to SQL literal.
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
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
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
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 |