sparkling/types
Types
DateTime64 with configurable precision and timezone.
Precision: 0-9 digits after decimal point (subsecond precision). Timezone: optional timezone identifier (e.g. “UTC”, “America/New_York”).
pub type DateTime64 {
DateTime64(
value: String,
precision: Int,
timezone: option.Option(String),
)
}
Constructors
-
DateTime64( value: String, precision: Int, timezone: option.Option(String), )
Decimal value with precision and scale preservation.
Stored as string to avoid floating-point precision loss. Use helper functions to convert to/from numeric types when needed.
pub opaque type Decimal
Enum16 type mapping (Int16 range: -32768..32767).
pub type Enum16 {
Enum16(mappings: List(#(String, Int)))
}
Constructors
-
Enum16(mappings: List(#(String, Int)))
Enum8 type mapping (Int8 range: -128..127).
pub type Enum8 {
Enum8(mappings: List(#(String, Int)))
}
Constructors
-
Enum8(mappings: List(#(String, Int)))
LowCardinality wrapper for values with low cardinality.
This is a performance hint to ClickHouse for storage optimization.
pub opaque type LowCardinality
Values
pub fn datetime64(
value: String,
precision: Int,
timezone: option.Option(String),
) -> Result(DateTime64, String)
Create a DateTime64 from an ISO 8601 string or epoch string.
pub fn datetime64_from_epoch(
epoch_seconds: Int,
precision: Int,
timezone: option.Option(String),
) -> Result(DateTime64, String)
Create a DateTime64 from Unix epoch (seconds).
pub fn datetime64_timezone(
dt: DateTime64,
) -> option.Option(String)
Get the timezone of a DateTime64.
pub fn datetime64_to_string(dt: DateTime64) -> String
Get the string representation of a DateTime64.
pub fn decimal(value: String) -> Result(Decimal, String)
Create a Decimal from a string representation.
pub fn decimal_from_float(
value: Float,
) -> Result(Decimal, String)
Create a Decimal from a float. Returns an error for values that cannot be represented as a plain decimal string (e.g. very large floats). Note: floats may lose precision; prefer decimal/1 with an explicit string.
pub fn decimal_from_int(value: Int) -> Decimal
Create a Decimal from an integer.
pub fn decimal_to_string(d: Decimal) -> String
Get the string representation of a Decimal.
pub fn enum16_from_string(
mappings: List(#(String, Int)),
value: String,
) -> Result(Int, String)
Look up an Enum16 value by string label. Returns an error if the label is not found or the mapped value is out of Int16 range [-32768, 32767].
pub fn enum8_from_string(
mappings: List(#(String, Int)),
value: String,
) -> Result(Int, String)
Look up an Enum8 value by string label. Returns an error if the label is not found or the mapped value is out of Int8 range [-128, 127].
pub fn low_cardinality_string(value: String) -> LowCardinality
Create a LowCardinality from a string value.
pub fn low_cardinality_value(lc: LowCardinality) -> String
Get the value from a LowCardinality wrapper.
pub fn uuid(value: String) -> Result(UUID, String)
Create a UUID from string representation.
pub fn uuid_to_string(u: UUID) -> String
Get the string representation of a UUID.