Skip to main content

Path

Struct Path 

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

Source

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);
Source

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);
Source

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");
Source

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");
Source

pub fn gt(self, rhs: impl IntoExpr<U>) -> Expr<bool>

Test whether this field is greater than rhs.

§Examples
let filter = User::fields().id().gt(10);
Source

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);
Source

pub fn lt(self, rhs: impl IntoExpr<U>) -> Expr<bool>

Test whether this field is less than rhs.

§Examples
let filter = User::fields().id().lt(100);
Source

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);
Source

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);
Source

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]);
Source

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);
Source

pub fn asc(self) -> OrderByExpr

Produce an ascending OrderByExpr for this path.

§Examples
let q = User::all()
    .order_by(User::fields().name().asc());
Source

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

Source

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"));
Source

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.

Source

pub fn contains(self, value: impl IntoExpr<U>) -> Expr<bool>

Test whether the array contains value.

Mirrors [Vec::contains]. Lowers to value = ANY(col) on PostgreSQL.

§Examples
ⓘ
let filter = User::fields().tags().contains("admin");
Source

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).

Source

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).

Source

pub fn len(self) -> Expr<i64>

Returns the array length.

Mirrors Vec::len. Lowers to cardinality(col) on PostgreSQL.

Source

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, Option<U>>

Source

pub fn is_none(self) -> Expr<bool>

Test whether this optional field is NULL.

§Examples
let filter = User::fields().bio().is_none();
Source

pub fn is_some(self) -> Expr<bool>

Test whether this optional field is not NULL.

§Examples
let filter = User::fields().bio().is_some();
Source§

impl<T, U> Path<T, U>
where U: Field<Inner = String>,

Source

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());
Source

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());
Source

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());
Source

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.
  • escape followed by %, _, or escape matches 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(), '\\');
Source

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.
  • escape followed by %, _, or escape matches 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(), '\\');

Trait Implementations§

Source§

impl<T, U> Clone for Path<T, U>

Source§

fn clone(&self) -> Path<T, U>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, U> Debug for Path<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T, U> IntoExpr<U> for Path<T, U>

Source§

fn into_expr(self) -> Expr<U>

Consume self and produce an Expr<T>. Read more
Source§

fn by_ref(&self) -> Expr<U>

Produce an Expr<T> from a reference without consuming self. Read more

Auto Trait Implementations§

§

impl<T, U> Freeze for Path<T, U>

§

impl<T, U> RefUnwindSafe for Path<T, U>

§

impl<T, U> Send for Path<T, U>
where T: Send, U: Send,

§

impl<T, U> Sync for Path<T, U>
where T: Sync, U: Sync,

§

impl<T, U> Unpin for Path<T, U>
where T: Unpin, U: Unpin,

§

impl<T, U> UnsafeUnpin for Path<T, U>

§

impl<T, U> UnwindSafe for Path<T, U>
where T: UnwindSafe, U: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more