Skip to main content

Query

Trait Query 

Source
pub trait Query: Sized {
    type Wrapper<T>;
    type Based: AsTable;

    // Required method
    fn query_with_context<T: FromQuery<Based = Self::Based>>(
        self,
        sql: RawSql<T>,
    ) -> Result<Self::Wrapper<T>>;

    // Provided method
    fn query<T: FromQuery<Based = Self::Based>>(
        self,
    ) -> Result<Self::Wrapper<T>> { ... }
}
Available on crate feature utils only.
Expand description

Core query execution trait. Implementors can call .query() to run SQL and retrieve results.

You generally do not implement this trait directly; use the concrete query builders (e.g. PostQuery, AuthorQuery).

The decorator wrappers Paginated, WithTotal, and Sorted all implement this trait by wrapping and delegating.

Required Associated Types§

Source

type Wrapper<T>

The wrapper type for query results. For most builders this is Vec<T>; when wrapped by WithTotal it becomes Totalled<Vec<T>>.

Source

type Based: AsTable

The database table type this query targets.

Required Methods§

Source

fn query_with_context<T: FromQuery<Based = Self::Based>>( self, sql: RawSql<T>, ) -> Result<Self::Wrapper<T>>

Execute the query with an externally supplied RawSql context (typically threaded through decorator layers).

Provided Methods§

Source

fn query<T: FromQuery<Based = Self::Based>>(self) -> Result<Self::Wrapper<T>>

Execute the query with a default empty RawSql context, returning all matching results.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§