pub struct Query<T>where
T: DataResult,{ /* private fields */ }
Expand description
Representation of a database query.
Implementations§
source§impl<T> Query<T>where
T: DataResult,
impl<T> Query<T>where T: DataResult,
sourcepub fn new(table: &'static str) -> Query<T>
pub fn new(table: &'static str) -> Query<T>
Creates a query which matches all objects in table
. The set
of matched objects can be restricted with filter
and
limit
.
sourcepub fn filter(self, expr: BoolExpr) -> Query<T>
pub fn filter(self, expr: BoolExpr) -> Query<T>
Restricts the query to matching only objects for which expr
is true. Returns self
as this method is expected to be
chained.
sourcepub fn limit(self, lim: i32) -> Query<T>
pub fn limit(self, lim: i32) -> Query<T>
Limits the query to matching the first lim
objects. Returns
self
as this method is expected to be chained.
sourcepub fn offset(self, off: i32) -> Query<T>
pub fn offset(self, off: i32) -> Query<T>
Skips the first off
objects before returning them. Returns
self
as this method is expected to be chained.
sourcepub fn order(self, column: &'static str, direction: OrderDirection) -> Query<T>
pub fn order(self, column: &'static str, direction: OrderDirection) -> Query<T>
Order the query results by the given column. Multiple calls to
this method may be made, with earlier calls taking precedence.
It is recommended to use the colname!
macro to construct the column name in a type-safe manner.
sourcepub fn order_asc(self, column: &'static str) -> Query<T>
pub fn order_asc(self, column: &'static str) -> Query<T>
Shorthand for order(column, OrderDirection::Ascending)
sourcepub fn order_desc(self, column: &'static str) -> Query<T>
pub fn order_desc(self, column: &'static str) -> Query<T>
Shorthand for order(column, OrderDirection::Descending)
sourcepub fn load_first(
self,
conn: &impl ConnectionMethods
) -> Result<Option<T>, Error>
pub fn load_first( self, conn: &impl ConnectionMethods ) -> Result<Option<T>, Error>
Executes the query against conn
and returns the first result (if any).