AshScylla.DataLayer.Udt (AshScylla v0.10.2)

Copy Markdown View Source

User Defined Type (UDT) runtime support for ScyllaDB.

Handles encoding/decoding UDT values for Xandra, CQL generation for UDT operations, and UDT schema management.

ScyllaDB UDTs are represented as tuples in Xandra. A UDT {field1_val, field2_val} maps to a map %{field1: val1, field2: val2}.

Summary

Functions

Generates CQL for altering a UDT (add/rename fields)

Generates CQL for creating a UDT

Decodes a UDT tuple from Xandra into a map

Generates CQL for dropping a UDT

Encodes a map value into UDT format for Xandra

Returns the CQL type string for a UDT field type

Generates CQL to list all UDTs in keyspace

Returns all UDTs defined in a resource's attributes

Generates CQL to check if UDT exists

Validates a UDT field specification

Types

udt_field_spec()

@type udt_field_spec() :: {atom(), atom()}

udt_schema()

@type udt_schema() :: %{
  name: atom(),
  type_name: String.t(),
  fields: [udt_field_spec()]
}

Functions

alter_type_cql(type_name, atom, fields)

@spec alter_type_cql(String.t() | atom(), :add | :rename, [udt_field_spec()]) ::
  String.t()

Generates CQL for altering a UDT (add/rename fields)

create_type_cql(type_name, fields)

@spec create_type_cql(String.t() | atom(), [udt_field_spec()]) :: String.t()

Generates CQL for creating a UDT

decode(tuple, resource)

@spec decode(tuple(), module()) :: map()

Decodes a UDT tuple from Xandra into a map

drop_type_cql(type_name)

@spec drop_type_cql(String.t() | atom()) :: String.t()

Generates CQL for dropping a UDT

encode(map, resource)

@spec encode(map(), module()) :: tuple()

Encodes a map value into UDT format for Xandra

field_type_to_cql(type)

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

Returns the CQL type string for a UDT field type

list_types_cql()

@spec list_types_cql() :: String.t()

Generates CQL to list all UDTs in keyspace

resource_udts(resource)

@spec resource_udts(module()) :: [udt_schema()]

Returns all UDTs defined in a resource's attributes

type_exists_cql(type_name)

@spec type_exists_cql(String.t() | atom()) :: String.t()

Generates CQL to check if UDT exists

validate_fields(fields)

@spec validate_fields([udt_field_spec()]) :: :ok | {:error, String.t()}

Validates a UDT field specification