Class: ClickhouseRuby::Types::Nullable
- Defined in:
- lib/clickhouse_ruby/types/nullable.rb
Overview
Type handler for ClickHouse Nullable type
Nullable wraps another type to allow NULL values. Without Nullable, ClickHouse columns cannot contain NULL.
Instance Attribute Summary collapse
-
#element_type ⇒ Base
readonly
The wrapped type.
Attributes inherited from Base
Instance Method Summary collapse
-
#cast(value) ⇒ Object?
Converts a Ruby value, allowing nil.
-
#deserialize(value) ⇒ Object?
Converts a value from ClickHouse, allowing nil.
-
#initialize(name, element_type: nil) ⇒ Nullable
constructor
A new instance of Nullable.
-
#nullable? ⇒ Boolean
Returns true - this type allows NULL.
-
#serialize(value) ⇒ String
Converts a value to SQL literal, handling NULL.
-
#to_s ⇒ String
Returns the full type string.
Methods inherited from Base
Constructor Details
Instance Attribute Details
#element_type ⇒ Base (readonly)
Returns the wrapped type.
18 19 20 |
# File 'lib/clickhouse_ruby/types/nullable.rb', line 18 def element_type @element_type end |
Instance Method Details
#cast(value) ⇒ Object?
Converts a Ruby value, allowing nil
31 32 33 34 35 |
# File 'lib/clickhouse_ruby/types/nullable.rb', line 31 def cast(value) return nil if value.nil? @element_type.cast(value) end |
#deserialize(value) ⇒ Object?
Converts a value from ClickHouse, allowing nil
41 42 43 44 45 46 |
# File 'lib/clickhouse_ruby/types/nullable.rb', line 41 def deserialize(value) return nil if value.nil? return nil if value.is_a?(::String) && value == '\\N' @element_type.deserialize(value) end |
#nullable? ⇒ Boolean
Returns true - this type allows NULL
61 62 63 |
# File 'lib/clickhouse_ruby/types/nullable.rb', line 61 def nullable? true end |
#serialize(value) ⇒ String
Converts a value to SQL literal, handling NULL
52 53 54 55 56 |
# File 'lib/clickhouse_ruby/types/nullable.rb', line 52 def serialize(value) return 'NULL' if value.nil? @element_type.serialize(value) end |
#to_s ⇒ String
Returns the full type string
68 69 70 |
# File 'lib/clickhouse_ruby/types/nullable.rb', line 68 def to_s "Nullable(#{@element_type})" end |