pub struct Path<T, U> { /* private fields */ }Expand description
A typed path from a root model T to a field of type U.
Path represents a traversal through a model’s fields and relations. The
type parameter T is the root model the path starts from, and U is the
type of the value at the end of the path.
Paths are the primary way to reference model fields in queries. Generated
code provides accessor methods (e.g., User::fields().name()) that return
paths, which you then use with comparison methods to build filter
expressions:
// Path<User, String> — the "name" field on User
let path = User::fields().name();
// Expr<bool> — a filter expression
let filter = path.eq("Alice");Paths can also be used to construct order-by clauses via
asc and desc, and can be chained to
navigate through relations with chain.
Implementations§
Source§impl<T, U> Path<T, U>
impl<T, U> Path<T, U>
Sourcepub fn into_variant(self, variant_id: VariantId) -> Path<T, U>
pub fn into_variant(self, variant_id: VariantId) -> Path<T, U>
Converts this path into a variant-rooted path for use in .matches()
closures on embedded enum fields.
§Examples
let path = User::path_field::<String>(1);
let variant_id = VariantId { model: ModelId(0), index: 0 };
let _variant_path = path.into_variant(variant_id);Sourcepub fn chain<X, V>(self, other: impl Into<Path<X, V>>) -> Path<T, V>
pub fn chain<X, V>(self, other: impl Into<Path<X, V>>) -> Path<T, V>
Append other to this path, producing a new path from T to V.
The origin of other is left unconstrained because list field structs
store Path<Origin, List<M>> while chaining segments rooted at M
(not List<M>). The untyped path concatenation is always correct; the
generic parameters serve only as compile-time markers.
§Examples
use toasty::stmt::Path;
use toasty::schema::Model;
let user_path = User::path_root();
let name_path = User::path_field::<String>(1);
let _chained: Path<User, String> = user_path.chain(name_path);Sourcepub fn eq(self, rhs: impl IntoExpr<U>) -> Expr<bool>
pub fn eq(self, rhs: impl IntoExpr<U>) -> Expr<bool>
Test whether this field equals rhs.
For a variant-rooted path (e.g. contact().email().address()), the
resulting filter implicitly requires the variant to match — it
expands to is_email(contact) AND address == rhs.
§Examples
let filter = User::fields().name().eq("Alice");Sourcepub fn ne(self, rhs: impl IntoExpr<U>) -> Expr<bool>
pub fn ne(self, rhs: impl IntoExpr<U>) -> Expr<bool>
Test whether this field does not equal rhs.
§Examples
let filter = User::fields().name().ne("Alice");Sourcepub fn ge(self, rhs: impl IntoExpr<U>) -> Expr<bool>
pub fn ge(self, rhs: impl IntoExpr<U>) -> Expr<bool>
Test whether this field is greater than or equal to rhs.
§Examples
let filter = User::fields().id().ge(1);Sourcepub fn le(self, rhs: impl IntoExpr<U>) -> Expr<bool>
pub fn le(self, rhs: impl IntoExpr<U>) -> Expr<bool>
Test whether this field is less than or equal to rhs.
§Examples
let filter = User::fields().id().le(100);Sourcepub fn between(
self,
low: impl IntoExpr<U>,
high: impl IntoExpr<U>,
) -> Expr<bool>
pub fn between( self, low: impl IntoExpr<U>, high: impl IntoExpr<U>, ) -> Expr<bool>
Test whether this field’s value is in the inclusive range [low, high].
Generates a BETWEEN low AND high condition in SQL and a native
BETWEEN condition expression in DynamoDB.
§Examples
let filter = User::fields().id().between(18_i64, 65_i64);Sourcepub fn in_list(self, rhs: impl IntoExpr<List<U>>) -> Expr<bool>
pub fn in_list(self, rhs: impl IntoExpr<List<U>>) -> Expr<bool>
Test whether this field’s value is in rhs.
rhs can be any collection that implements IntoExpr<List<U>>, such
as a Vec, array, or slice.
§Examples
let filter = User::fields().id().in_list([1_i64, 2, 3]);Sourcepub fn in_query<Q>(self, rhs: Q) -> Expr<bool>where
Q: IntoStatement<Returning = List<U>>,
pub fn in_query<Q>(self, rhs: Q) -> Expr<bool>where
Q: IntoStatement<Returning = List<U>>,
Test whether this field’s value appears in the result set of a subquery.
§Examples
use toasty::stmt::{List, Query};
use toasty::schema::Model;
// A path targeting User values
let path = User::path_root();
// A subquery returning List<User>
let subquery = Query::<List<User>>::all().filter(User::fields().name().eq("Alice"));
let filter = path.in_query(subquery);Sourcepub fn asc(self) -> OrderByExpr
pub fn asc(self) -> OrderByExpr
Produce an ascending OrderByExpr for this path.
§Examples
let q = User::all()
.order_by(User::fields().name().asc());Sourcepub fn desc(self) -> OrderByExpr
pub fn desc(self) -> OrderByExpr
Produce a descending OrderByExpr for this path.
§Examples
let q = User::all()
.order_by(User::fields().name().desc());Source§impl<T, U> Path<T, List<U>>
impl<T, U> Path<T, List<U>>
Sourcepub fn any(self, filter: Expr<bool>) -> Expr<bool>where
U: Model,
pub fn any(self, filter: Expr<bool>) -> Expr<bool>where
U: Model,
Build an IN subquery expression that tests whether any associated
record satisfies filter.
The path must point to a HasMany (or similar collection) field on the
parent model. The returned expression can be used as a filter on the
parent query.
§Examples
use toasty::stmt::List;
use toasty::schema::Model;
// Find users that have at least one todo with "urgent" in the title
let todos_path = User::path_field::<List<Todo>>(2);
let filter = todos_path.any(Todo::fields().title().eq("urgent"));Sourcepub fn all(self, filter: Expr<bool>) -> Expr<bool>where
U: Model,
pub fn all(self, filter: Expr<bool>) -> Expr<bool>where
U: Model,
Build a NOT IN subquery expression that tests whether all associated
records satisfy filter.
The path must point to a HasMany (or similar collection) field on the
parent model. Returns true when every associated record matches
filter, including the vacuous case where the parent has no associated
records (matching Rust’s [].iter().all() semantics).
§Examples
use toasty::stmt::List;
use toasty::schema::Model;
// Find users whose todos are all complete
let todos_path = User::path_field::<List<Todo>>(2);
let filter = todos_path.all(Todo::fields().complete().eq(true));Source§impl<T, U> Path<T, List<U>>where
U: Scalar,
Container-style predicates on a Vec<scalar> model field. The path target
is the List<U> marker (matching Field::Path<Origin> for Vec<U>),
and the element type U is constrained to a path-target scalar so the
same IntoExpr infrastructure that powers eq/in_list covers the
right-hand side.
impl<T, U> Path<T, List<U>>where
U: Scalar,
Container-style predicates on a Vec<scalar> model field. The path target
is the List<U> marker (matching Field::Path<Origin> for Vec<U>),
and the element type U is constrained to a path-target scalar so the
same IntoExpr infrastructure that powers eq/in_list covers the
right-hand side.
Sourcepub fn is_superset(self, values: impl IntoExpr<List<U>>) -> Expr<bool>
pub fn is_superset(self, values: impl IntoExpr<List<U>>) -> Expr<bool>
Test whether the array contains every element of values.
Mirrors HashSet::is_superset.
Lowers to col @> values (PostgreSQL @> operator).
Sourcepub fn intersects(self, values: impl IntoExpr<List<U>>) -> Expr<bool>
pub fn intersects(self, values: impl IntoExpr<List<U>>) -> Expr<bool>
Test whether the array shares at least one element with values.
Negation of HashSet::is_disjoint.
Lowers to col && values (PostgreSQL && operator).
Sourcepub fn len(self) -> Expr<i64>
pub fn len(self) -> Expr<i64>
Returns the array length.
Mirrors Vec::len. Lowers to cardinality(col) on PostgreSQL.
Sourcepub fn is_empty(self) -> Expr<bool>
pub fn is_empty(self) -> Expr<bool>
Returns true if the array is empty.
Equivalent to .len().eq(0). Mirrors Vec::is_empty.
Source§impl<T, U> Path<T, U>
impl<T, U> Path<T, U>
Sourcepub fn starts_with(self, prefix: impl IntoExpr<String>) -> Expr<bool>
pub fn starts_with(self, prefix: impl IntoExpr<String>) -> Expr<bool>
Test whether this string field starts with prefix.
Available on any string-valued field, including String,
Option<String>, and other wrappers whose Field::Inner is String.
For DynamoDB, this maps to begins_with in a KeyConditionExpression
(sort key) or FilterExpression (non-key attribute).
§Examples
let filter = User::fields().name().starts_with("Al".to_string());
let filter = User::fields().nickname().starts_with("Al".to_string());Sourcepub fn like(self, pattern: impl IntoExpr<String>) -> Expr<bool>
pub fn like(self, pattern: impl IntoExpr<String>) -> Expr<bool>
Test whether this string field matches a SQL LIKE pattern.
Available on any string-valued field, including String,
Option<String>, and other wrappers whose Field::Inner is String.
The caller is responsible for including any % or _ wildcard
characters in pattern. Not supported by the DynamoDB driver — use
starts_with instead.
.like() is a pass-through to the database’s own LIKE, whose case
sensitivity differs by backend: case-sensitive on PostgreSQL,
case-insensitive for ASCII on SQLite, and collation-dependent on MySQL.
For a case-insensitive match on PostgreSQL, use ilike.
§Examples
let filter = User::fields().name().like("Al%".to_string());
let filter = User::fields().nickname().like("Al%".to_string());Sourcepub fn ilike(self, pattern: impl IntoExpr<String>) -> Expr<bool>
pub fn ilike(self, pattern: impl IntoExpr<String>) -> Expr<bool>
Case-insensitive variant of like, mapping to
PostgreSQL’s ILIKE operator.
PostgreSQL is the only supported backend with a native ILIKE, so
.ilike() works only there. Toasty does not emulate it: on MySQL,
SQLite, and DynamoDB the query is rejected with an unsupported-feature
error. PostgreSQL’s LIKE is case-sensitive and so provides ILIKE as
its case-insensitive companion; the other backends fold ASCII case in
LIKE (SQLite) or set it through the column collation (MySQL), so there
is no operator with matching semantics for .ilike() to pass through to.
§Examples
// Matches "Alice", "ALICIA", and "alfred".
let filter = User::fields().name().ilike("al%".to_string());Sourcepub fn like_with_escape(
self,
pattern: impl IntoExpr<String>,
escape: char,
) -> Expr<bool>
pub fn like_with_escape( self, pattern: impl IntoExpr<String>, escape: char, ) -> Expr<bool>
Test whether this string field matches a SQL LIKE pattern using an
explicit escape character.
Available on any string-valued field, including String,
Option<String>, and other wrappers whose Field::Inner is String.
The caller is responsible for constructing the LIKE pattern. Toasty does
not escape pattern automatically. Any % or _ characters that are not
escaped by escape are treated as SQL LIKE wildcards:
%matches any sequence of characters._matches any single character.escapefollowed by%,_, orescapematches that character literally.
This is useful when the pattern needs to match literal % or _
characters. For example, with escape set to '\\', the pattern
"Alice\\%%" matches strings beginning with the literal text "Alice%".
The first % is escaped and matched literally; the second % remains a
wildcard.
Not supported by the DynamoDB driver. Use starts_with
instead when targeting DynamoDB.
.like_with_escape() is a pass-through to the database’s own LIKE
operator with an ESCAPE clause. Case sensitivity differs by backend:
case-sensitive on PostgreSQL, case-insensitive for ASCII on SQLite, and
collation-dependent on MySQL. For a case-insensitive match on PostgreSQL,
use ilike.
§Examples
// Match names starting with "Al".
let filter = User::fields().name().like_with_escape("Al%".to_string(), '\\');
// Match names starting with the literal text "Alice%".
let filter = User::fields().name().like_with_escape("Alice\\%%".to_string(), '\\');
// Also works on nullable string fields.
let filter = User::fields().nickname().like_with_escape("Al%".to_string(), '\\');Sourcepub fn ilike_with_escape(
self,
pattern: impl IntoExpr<String>,
escape: char,
) -> Expr<bool>
pub fn ilike_with_escape( self, pattern: impl IntoExpr<String>, escape: char, ) -> Expr<bool>
Test whether this string field matches a case-insensitive SQL LIKE
pattern using an explicit escape character.
This is the escaped variant of ilike. It maps to
PostgreSQL’s ILIKE ... ESCAPE ... syntax.
PostgreSQL is the only supported backend with a native ILIKE, so
.ilike_with_escape() works only there. Toasty does not emulate it: on
MySQL, SQLite, and DynamoDB the query is rejected with an
unsupported-feature error.
The caller is responsible for constructing the ILIKE pattern. Toasty does
not escape pattern automatically. Any % or _ characters that are not
escaped by escape are treated as SQL pattern wildcards:
%matches any sequence of characters._matches any single character.escapefollowed by%,_, orescapematches that character literally.
This is useful when the pattern needs to match literal % or _
characters while still matching case-insensitively. For example, with
escape set to '\\', the pattern "Alice\\%%" matches strings beginning
with the literal text "Alice%", ignoring case. It can match "Alice%1",
"ALICE%1", or "alice%foo", but not "AliceA1".
§Examples
// Match names starting with "al", ignoring case.
let filter = User::fields().name().ilike_with_escape("al%".to_string(), '\\');
// Match names starting with the literal text "alice%", ignoring case.
let filter = User::fields().name().ilike_with_escape("alice\\%%".to_string(), '\\');