pub struct Query<T>where
T: DataResult,{ /* private fields */ }
Expand description
Representation of a database query.
See QueryOpsSync
and QueryOpsAsync
for operations requiring a live database connection.
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)
Trait Implementations§
Source§impl<T> Clone for Query<T>where
T: DataResult,
impl<T> Clone for Query<T>where
T: DataResult,
Source§impl<T> QueryOpsAsync<T> for Query<T>where
T: DataResult,
impl<T> QueryOpsAsync<T> for Query<T>where
T: DataResult,
Source§async fn load_first(
self,
conn: &impl ConnectionMethodsAsync,
) -> Result<Option<T>, Error>
async fn load_first( self, conn: &impl ConnectionMethodsAsync, ) -> Result<Option<T>, Error>
conn
and returns the first result (if any).Source§impl<T> QueryOpsSync<T> for Query<T>where
T: DataResult,
impl<T> QueryOpsSync<T> for Query<T>where
T: DataResult,
Source§fn load_first(self, conn: &impl ConnectionMethods) -> Result<Option<T>, Error>
fn load_first(self, conn: &impl ConnectionMethods) -> Result<Option<T>, Error>
conn
and returns the first result (if any).