AshClickhouse.DataLayer.Types (AshClickhouse v0.1.0)

Copy Markdown View Source

Mapping between Ash attribute types and ClickHouse column types.

ClickHouse is a strongly-typed columnar store. When generating CREATE TABLE statements and when encoding query parameters, the data layer needs to know the ClickHouse type that corresponds to each Ash attribute.

The mapping here favours ClickHouse types that are safe and broadly useful:

Ash typeClickHouse type
:uuidUUID
:string / :atom / :ci_stringString
:integerInt64
:floatFloat64
:booleanUInt8
:utc_datetime / :naive_datetimeDateTime / DateTime64
:dateDate
:timeString
:decimalDecimal
:mapMap(String, String)
:array / :listArray(String)

Summary

Functions

Maps an Ash attribute type to a ClickHouse column type string.

Returns the set of attribute names (atom) that are Atom-typed.

Builds a map of attribute name => ClickHouse type string for a resource.

Resolves the ClickHouse type for an Ash attribute struct, preferring the attribute's storage_type/1 when available.

Returns the set of attribute names (atom and string) that are UUID-typed.

Converts a 16-byte UUID binary to its canonical 36-character string form.

Returns true if the given binary looks like a canonical UUID string.

Converts a 36-character UUID string to its 16-byte binary form for ClickHouse.

Functions

ash_type_to_clickhouse(type)

@spec ash_type_to_clickhouse(atom() | tuple() | module()) :: String.t()

Maps an Ash attribute type to a ClickHouse column type string.

atom_attribute_names(resource)

@spec atom_attribute_names(module()) :: MapSet.t(atom())

Returns the set of attribute names (atom) that are Atom-typed.

attr_type_map(resource)

@spec attr_type_map(module()) :: %{required(atom() | String.t()) => String.t()}

Builds a map of attribute name => ClickHouse type string for a resource.

resolve_attr_type(attr)

@spec resolve_attr_type(map()) :: String.t()

Resolves the ClickHouse type for an Ash attribute struct, preferring the attribute's storage_type/1 when available.

uuid_attribute_names(resource)

@spec uuid_attribute_names(module()) :: MapSet.t()

Returns the set of attribute names (atom and string) that are UUID-typed.

uuid_binary_to_string(value)

@spec uuid_binary_to_string(binary()) :: {:ok, String.t()} | :error

Converts a 16-byte UUID binary to its canonical 36-character string form.

uuid_like_string?(value)

@spec uuid_like_string?(term()) :: boolean()

Returns true if the given binary looks like a canonical UUID string.

uuid_string_to_binary(value)

@spec uuid_string_to_binary(String.t()) :: {:ok, binary()} | :error

Converts a 36-character UUID string to its 16-byte binary form for ClickHouse.