UserType
User-Defined Type (UDT) base class and utilities.
User-Defined Type (UDT) support for coodie.
Provides a UserType(BaseModel) base class for declaring Cassandra/ScyllaDB
UDTs using standard Pydantic type annotations.
Example:
from coodie.usertype import UserType
class Address(UserType):
street: str
city: str
zipcode: int
class Settings:
__type_name__ = "address" # optional — defaults to snake_case
keyspace = "my_ks"
- class coodie.usertype.UserType
Bases:
BaseModelBase class for Cassandra/ScyllaDB User-Defined Types.
Subclass this with standard Pydantic field annotations to define a UDT:
class Address(UserType): street: str city: str zipcode: int
- classmethod type_name() str
Return the CQL type name for this UDT.
Uses
Settings.__type_name__if set, otherwise converts the class name to snake_case (HTTPAddress->http_address).
- classmethod sync_type(keyspace: str | None = None, dry_run: bool = False) list[str]
Synchronously create or update this UDT in the database.
Syncs nested UDT dependencies first. Fields missing from the database type are added with
ALTER TYPE ... ADD; removed fields and type changes are only logged (UDT fields are never dropped or altered).- Returns:
List of DDL statements that were (or, with
dry_run, would be) executed.
- async classmethod sync_type_async(keyspace: str | None = None, dry_run: bool = False) list[str]
Async version of
sync_type().
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- coodie.usertype.extract_udt_classes(doc_cls: type) list[type[UserType]]
Return all
UserTypesubclasses used by a Document, topologically sorted.Scans the Document’s type hints for UDT references (direct fields, inside collections, nested UDTs) and returns them in dependency order suitable for sequential
sync_type()calls.