Shared CQL type mapping and conversion helpers.
Centralizes the canonical type-to-CQL-string mappings used across
AshScylla.Migration, AshScylla.DataLayer.Udt, and
AshScylla.DataLayer.Collection.
Summary
Functions
Converts an Ash type (atom or tuple) to its CQL type string representation.
Returns the CQL type string for a collection element type atom.
Returns the CQL type string for a given type atom.
Returns the CQL type string for a UDT field type atom.
Converts a 16-byte UUID binary from Xandra/ScyllaDB back to a 36-character UUID string (e.g. "550e8400-e29b-41d4-a716-446655440000").
Converts a UUID string (36 chars, e.g. "550e8400-e29b-41d4-a716-446655440000") to a 16-byte binary for Xandra/ScyllaDB.
Returns the list of all known valid CQL type atoms.
Functions
Converts an Ash type (atom or tuple) to its CQL type string representation.
Handles special collection and structured types:
:map— rendered asMAP<key_type, value_type>:array— rendered asLIST<element_type>:set— rendered asSET<element_type>:udt— rendered asfrozen<type_name>{:array, element_type}— rendered asLIST<cql_type>{:map, key_type, value_type}— rendered asMAP<k, v>{:set, element_type}— rendered asSET<cql_type>
All other atoms are resolved via the canonical cql_type/1 mapping.
The :frozen option wraps the result in frozen<...>.
Options
:key_type— for:map, the CQL key type (default:"TEXT"):value_type— for:map, the CQL value type (default:"TEXT"):element_type— for:array/:set, the CQL element type (default:"TEXT"):type_name— for:udt, the UDT name:frozen— iftrue, wraps the result infrozen<...>
Examples
iex> AshScylla.DataLayer.Types.ash_type_to_cql_type(:uuid, [])
"UUID"
iex> AshScylla.DataLayer.Types.ash_type_to_cql_type(:string, [])
"TEXT"
iex> AshScylla.DataLayer.Types.ash_type_to_cql_type(:map, key_type: "TEXT", value_type: "INT")
"MAP<TEXT, INT>"
iex> AshScylla.DataLayer.Types.ash_type_to_cql_type(:array, element_type: "UUID")
"LIST<UUID>"
iex> AshScylla.DataLayer.Types.ash_type_to_cql_type({:array, :string}, [])
"LIST<TEXT>"
iex> AshScylla.DataLayer.Types.ash_type_to_cql_type({:map, :string, :integer}, [])
"MAP<TEXT, BIGINT>"
Returns the CQL type string for a collection element type atom.
Delegates to cql_type/1.
Examples
iex> AshScylla.DataLayer.Types.cql_element_type(:int)
"INT"
iex> AshScylla.DataLayer.Types.cql_element_type(:float)
"FLOAT"
Returns the CQL type string for a given type atom.
Known types are resolved via the canonical mapping. Unknown types fall back to "TEXT".
Examples
iex> AshScylla.DataLayer.Types.cql_type(:text)
"TEXT"
iex> AshScylla.DataLayer.Types.cql_type(:bigint)
"BIGINT"
iex> AshScylla.DataLayer.Types.cql_type(:custom_type)
"TEXT"
Returns the CQL type string for a UDT field type atom.
Delegates to cql_type/1.
Examples
iex> AshScylla.DataLayer.Types.field_type_to_cql(:text)
"TEXT"
iex> AshScylla.DataLayer.Types.field_type_to_cql(:uuid)
"UUID"
Converts a 16-byte UUID binary from Xandra/ScyllaDB back to a 36-character UUID string (e.g. "550e8400-e29b-41d4-a716-446655440000").
Returns {:ok, String.t()} on success, :error if the binary is not 16 bytes.
Converts a UUID string (36 chars, e.g. "550e8400-e29b-41d4-a716-446655440000") to a 16-byte binary for Xandra/ScyllaDB.
Returns {:ok, binary} on success, :error if the string is not a valid UUID.
@spec valid_cql_types() :: [atom()]
Returns the list of all known valid CQL type atoms.