pub struct SelectQueryBuilder<'args, DB, Model>where
DB: Database,{
pub query: Select,
/* private fields */
}
Fields§
§query: Select
Implementations§
Source§impl<'args, DB, M> SelectQueryBuilder<'args, DB, M>
impl<'args, DB, M> SelectQueryBuilder<'args, DB, M>
pub async fn fetch_all<'executor, E>(self, db: E) -> Result<Vec<M>>where
E: Executor<'executor, Database = DB>,
pub async fn fetch_one<'executor, E>(self, db: E) -> Result<M>where
E: Executor<'executor, Database = DB>,
pub async fn fetch_optional<'executor, E>(self, db: E) -> Result<Option<M>>where
E: Executor<'executor, Database = DB>,
pub fn with(self, name: &str, query: &str) -> Self
Sourcepub fn select(self, column: impl Into<String>) -> Self
pub fn select(self, column: impl Into<String>) -> Self
Add a column to the query. Note you typically don’t need this, as creating a query from
Model::select
will automatically add that model’s columns.
§Arguments
column
- The column to add. Examples: “id”, “name”, “person.*”
Sourcepub fn where_(self, clause: &'static str) -> Self
pub fn where_(self, clause: &'static str) -> Self
Add a WHERE clause to the query.
Do not use format! to add parameters. Instead, use ?
as the placeholder, and add
parameters with bind
.
Postgres users: You can (and should) use ?
as the placeholder. You might not have a defined
numerical order for your parameters, preventing $?
with $<N>
. If you need the same parameter multiple times, you should
bind it multiple times. Arguments aren’t moved, so this doesn’t incur a memory cost. If you
still want to re-use parameters, you can use $?
and
$<N>
placeholders, as they will conflict.
§Arguments
clause
- The clause to add. Examples: “id = ?”, “name = ?”, “person.id = ?”
Sourcepub fn where_bind<T>(self, clause: &'static str, value: T) -> Self
pub fn where_bind<T>(self, clause: &'static str, value: T) -> Self
Convenience method to add a WHERE
and bind a value in one call.
Sourcepub fn where_bind_option<T>(
self,
clause: &'static str,
value: Option<T>,
) -> Self
pub fn where_bind_option<T>( self, clause: &'static str, value: Option<T>, ) -> Self
Convenience method to add a WHERE
and bind a optional value in one call.
If Option is None, this clause will not be pushed
Sourcepub fn dangerous_where(self, clause: &str) -> Self
pub fn dangerous_where(self, clause: &str) -> Self
Dangerous because it takes a string that could be user crafted. You should prefer .where_
which
takes a &’static str, and pass arguments with .bind()
.
pub fn join(self, join_description: JoinDescription) -> Self
Sourcepub fn group_by(self, clause: &str) -> Self
pub fn group_by(self, clause: &str) -> Self
Add a GROUP BY clause to the query.
§Arguments:
clause
: The GROUP BY clause to add. Examples: “id”, “id, date”, “1, 2, ROLLUP(3)”
Sourcepub fn order_by(self, clause: &str, direction: Direction) -> Self
pub fn order_by(self, clause: &str, direction: Direction) -> Self
Add an ORDER BY clause to the query.
§Arguments:
clause
: The ORDER BY clause to add. “created_at DESC”, “id ASC NULLS FIRST”direction
: Direction::Asc or Direction::Desc
pub fn order_asc(self, clause: &str) -> Self
pub fn order_desc(self, clause: &str) -> Self
pub fn into_query_and_args( self, ) -> Result<(String, QueryBuilderArgs<'args, DB>)>
Trait Implementations§
Auto Trait Implementations§
impl<'args, DB, Model> Freeze for SelectQueryBuilder<'args, DB, Model>
impl<'args, DB, Model> RefUnwindSafe for SelectQueryBuilder<'args, DB, Model>
impl<'args, DB, Model> Send for SelectQueryBuilder<'args, DB, Model>where
Model: Send,
impl<'args, DB, Model> Sync for SelectQueryBuilder<'args, DB, Model>
impl<'args, DB, Model> Unpin for SelectQueryBuilder<'args, DB, Model>where
Model: Unpin,
impl<'args, DB, Model> UnwindSafe for SelectQueryBuilder<'args, DB, Model>
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
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>
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>
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 more