QuerySet
QuerySet is the chainable query builder returned by Document.find().
It supports filtering, ordering, limiting, and terminal operations like
.all(), .first(), .count(), .delete(), and .update().
Sync API (coodie.sync)
- class coodie.sync.query.QuerySet(doc_cls: type[Document], *, where: list[tuple[str, str, Any]] | None = None, limit_val: int | None = None, order_by_val: list[str] | None = None, allow_filtering_val: bool = False, if_not_exists_val: bool = False, if_exists_val: bool = False, ttl_val: int | None = None, timestamp_val: int | None = None, consistency_val: str | None = None, timeout_val: float | None = None, only_val: list[str] | None = None, defer_val: list[str] | None = None, values_list_val: list[str] | None = None, per_partition_limit_val: int | None = None, fetch_size_val: int | None = None, paging_state_val: bytes | None = None, distinct_val: bool = False, group_by_val: list[str] | None = None, select_token_val: list[str] | None = None, cast_val: list[tuple[str, str]] | None = None, ann_of_val: tuple[str, list[float]] | None = None, validate_val: bool | None = None)
Bases:
objectSynchronous chainable query builder.
- order_by_ann(column: str, vector: list[float]) QuerySet
Order results by approximate nearest neighbor (ANN) similarity.
Generates
ORDER BY "column" ANN OF ?in the CQL query.- Parameters:
column – The vector column name.
vector – The query vector to compare against.
- using(*, ttl: int | None = None, timestamp: int | None = None, consistency: str | None = None, timeout: float | None = None) QuerySet
- validate(enabled: bool = True) QuerySet
Enable or disable Pydantic validation when hydrating rows.
By default, rows from the database are hydrated using
model_construct()which skips validation for speed. Call.validate()to switch tomodel_validate()which performs full type coercion and runs custom validators — useful when driver-returned types may not match model field types exactly.
- paged_all() PagedResult
Execute query returning a
PagedResultwith documents and paging state.When combined with
order_by_ann(), ScyllaDB ANN queries do not support cursor-based pagination and will always return a single page withpaging_state=None. Uselimit()to control the number of results.
- count() int
- aggregate(**funcs: str) dict[str, Any]
Execute one or more aggregate functions.
Each keyword argument maps a result name to a
"func(column)"expression. Example:result = qs.aggregate(total="sum(price)", avg_price="avg(price)") # result == {"total": 150.0, "avg_price": 30.0}
- sum(column: str) Any
- avg(column: str) Any
- min(column: str) Any
- max(column: str) Any
- json() list[str]
Execute
SELECT JSON * FROM …and return a list of JSON strings.
- writetime(column: str) Any
Execute
SELECT WRITETIME("col") FROM …and return the scalar result.
- column_ttl(column: str) Any
Execute
SELECT TTL("col") FROM …and return the scalar result.
- create(**kwargs: Any) LWTResult | None
Insert a new document. Respects
if_not_exists(),ttl(), andtimestamp()chain modifiers.
- update(ttl: int | None = None, if_conditions: dict[str, Any] | None = None, **kwargs: Any) None
Bulk UPDATE matching rows. TTL may be provided as a parameter or via the
ttl()chain modifier.
Async API (coodie.aio)
- class coodie.aio.query.QuerySet(doc_cls: type[Document], *, where: list[tuple[str, str, Any]] | None = None, limit_val: int | None = None, order_by_val: list[str] | None = None, allow_filtering_val: bool = False, if_not_exists_val: bool = False, if_exists_val: bool = False, ttl_val: int | None = None, timestamp_val: int | None = None, consistency_val: str | None = None, timeout_val: float | None = None, only_val: list[str] | None = None, defer_val: list[str] | None = None, values_list_val: list[str] | None = None, per_partition_limit_val: int | None = None, fetch_size_val: int | None = None, paging_state_val: bytes | None = None, distinct_val: bool = False, group_by_val: list[str] | None = None, select_token_val: list[str] | None = None, cast_val: list[tuple[str, str]] | None = None, ann_of_val: tuple[str, list[float]] | None = None, validate_val: bool | None = None)
Bases:
objectAsynchronous chainable query builder.
- order_by_ann(column: str, vector: list[float]) QuerySet
Order results by approximate nearest neighbor (ANN) similarity.
Generates
ORDER BY "column" ANN OF ?in the CQL query.- Parameters:
column – The vector column name.
vector – The query vector to compare against.
- using(*, ttl: int | None = None, timestamp: int | None = None, consistency: str | None = None, timeout: float | None = None) QuerySet
- validate(enabled: bool = True) QuerySet
Enable or disable Pydantic validation when hydrating rows.
By default, rows from the database are hydrated using
model_construct()which skips validation for speed. Call.validate()to switch tomodel_validate()which performs full type coercion and runs custom validators — useful when driver-returned types may not match model field types exactly.
- async paged_all() PagedResult
Execute query returning a
PagedResultwith documents and paging state.When combined with
order_by_ann(), ScyllaDB ANN queries do not support cursor-based pagination and will always return a single page withpaging_state=None. Uselimit()to control the number of results.
- async count() int
- async aggregate(**funcs: str) dict[str, Any]
Execute one or more aggregate functions.
Each keyword argument maps a result name to a
"func(column)"expression. Example:result = await qs.aggregate(total="sum(price)", avg_price="avg(price)") # result == {"total": 150.0, "avg_price": 30.0}
- async sum(column: str) Any
- async avg(column: str) Any
- async min(column: str) Any
- async max(column: str) Any
- async json() list[str]
Execute
SELECT JSON * FROM …and return a list of JSON strings.
- async writetime(column: str) Any
Execute
SELECT WRITETIME("col") FROM …and return the scalar result.
- async column_ttl(column: str) Any
Execute
SELECT TTL("col") FROM …and return the scalar result.
- async create(**kwargs: Any) LWTResult | None
Insert a new document. Respects
if_not_exists(),ttl(), andtimestamp()chain modifiers.
- async update(ttl: int | None = None, if_conditions: dict[str, Any] | None = None, **kwargs: Any) None
Bulk UPDATE matching rows. TTL may be provided as a parameter or via the
ttl()chain modifier.