Struct ormlite_core::query_builder::SelectQueryBuilder
source · 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>where
M: Sized + Send + Sync + Unpin + for<'r> FromRow<'r, DB::Row> + 'static + Model<DB>,
DB: Database + DatabaseMetadata,
<DB as HasArguments<'args>>::Arguments: IntoArguments<'args, DB>,
impl<'args, DB, M> SelectQueryBuilder<'args, DB, M>where M: Sized + Send + Sync + Unpin + for<'r> FromRow<'r, DB::Row> + 'static + Model<DB>, DB: Database + DatabaseMetadata, <DB as HasArguments<'args>>::Arguments: IntoArguments<'args, DB>,
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) -> Selfwhere
T: 'args + Send + Type<DB> + Encode<'args, DB>,
pub fn where_bind<T>(self, clause: &'static str, value: T) -> Selfwhere T: 'args + Send + Type<DB> + Encode<'args, DB>,
Convenience method to add a WHERE
and bind a value in one call.
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
sourcepub fn bind<T>(self, value: T) -> Selfwhere
T: 'args + Send + Type<DB> + Encode<'args, DB>,
pub fn bind<T>(self, value: T) -> Selfwhere T: 'args + Send + Type<DB> + Encode<'args, DB>,
Bind an argument to the query.