AshScylla.DataLayer.Types (AshScylla v0.9.0)

Copy Markdown View Source

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.

Returns the list of all known valid CQL type atoms.

Functions

ash_type_to_cql_type(type, opts)

@spec ash_type_to_cql_type(
  atom() | tuple(),
  keyword()
) :: String.t()

Converts an Ash type (atom or tuple) to its CQL type string representation.

Handles special collection and structured types:

  • :map — rendered as MAP<key_type, value_type>
  • :array — rendered as LIST<element_type>
  • :set — rendered as SET<element_type>
  • :udt — rendered as frozen<type_name>
  • {:array, element_type} — rendered as LIST<cql_type>
  • {:map, key_type, value_type} — rendered as MAP<k, v>
  • {:set, element_type} — rendered as SET<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 — if true, wraps the result in frozen<...>

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>"

cql_element_type(type)

@spec cql_element_type(atom()) :: String.t()

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"

cql_type(type)

@spec cql_type(atom()) :: String.t()

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"

field_type_to_cql(type)

@spec field_type_to_cql(atom()) :: String.t()

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"

valid_cql_types()

@spec valid_cql_types() :: [atom()]

Returns the list of all known valid CQL type atoms.