pub struct Query<T> { /* private fields */ }Available on crate feature
db only.Expand description
A query that can be executed on a database. Can be used to filter, update, or delete rows.
§Example
use cot::db::model;
use cot::db::query::Query;
#[model]
struct User {
#[model(primary_key)]
id: i32,
name: String,
age: i32,
}
let query = Query::<User>::new();Implementations§
Source§impl<T: Model> Query<T>
impl<T: Model> Query<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new query.
§Example
use cot::db::model;
use cot::db::query::Query;
#[model]
struct User {
#[model(primary_key)]
id: i32,
name: String,
age: i32,
}
let query = Query::<User>::new();Sourcepub fn filter(&mut self, filter: Expr) -> &mut Self
pub fn filter(&mut self, filter: Expr) -> &mut Self
Set the filter expression for the query.
§Example
use cot::db::model;
use cot::db::query::{Expr, Query};
#[model]
struct User {
#[model(primary_key)]
id: i32,
name: String,
age: i32,
}
let query = Query::<User>::new().filter(Expr::eq(Expr::field("name"), Expr::value("John")));Sourcepub fn limit(&mut self, limit: u64) -> &mut Self
pub fn limit(&mut self, limit: u64) -> &mut Self
Set the limit for the query.
§Example
use cot::db::model;
use cot::db::query::{Expr, Query};
#[model]
struct User {
#[model(primary_key)]
id: i32,
name: String,
age: i32,
}
let query = Query::<User>::new().limit(10);Sourcepub fn offset(&mut self, offset: u64) -> &mut Self
pub fn offset(&mut self, offset: u64) -> &mut Self
Set the offset for the query.
§Example
use cot::db::model;
use cot::db::query::{Expr, Query};
#[model]
struct User {
#[model(primary_key)]
id: i32,
name: String,
age: i32,
}
let query = Query::<User>::new().offset(10);Sourcepub async fn delete<DB: DatabaseBackend>(
&self,
db: &DB,
) -> Result<StatementResult>
pub async fn delete<DB: DatabaseBackend>( &self, db: &DB, ) -> Result<StatementResult>
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Query<T>
impl<T> RefUnwindSafe for Query<T>
impl<T> Send for Query<T>
impl<T> Sync for Query<T>
impl<T> Unpin for Query<T>
impl<T> UnwindSafe for Query<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoField<Auto<T>> for T
impl<T> IntoField<Auto<T>> for T
Source§fn into_field(self) -> Auto<T>
fn into_field(self) -> Auto<T>
Available on crate feature
db only.Converts the type to the field type.