pub trait QueryFragment<DB: Backend, SP = NotSpecialized> {
// Required method
fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()>;
// Provided methods
fn to_sql(
&self,
out: &mut DB::QueryBuilder,
backend: &DB,
) -> QueryResult<()> { ... }
fn collect_binds<'b>(
&'b self,
out: &mut DB::BindCollector<'b>,
metadata_lookup: &mut DB::MetadataLookup,
backend: &'b DB,
) -> QueryResult<()> { ... }
fn is_safe_to_cache_prepared(&self, backend: &DB) -> QueryResult<bool> { ... }
fn is_noop(&self, backend: &DB) -> QueryResult<bool> { ... }
}Expand description
An untyped fragment of SQL.
This may be a complete SQL command (such as an update statement without a
RETURNING clause), or a subsection (such as our internal types used to
represent a WHERE clause). Implementations of ExecuteDsl and
LoadQuery will generally require that this trait be implemented.
Required Methods§
Provided Methods§
Sourcefn to_sql(&self, out: &mut DB::QueryBuilder, backend: &DB) -> QueryResult<()>
fn to_sql(&self, out: &mut DB::QueryBuilder, backend: &DB) -> QueryResult<()>
Converts this QueryFragment to its SQL representation.
This method should only be called by implementations of Connection.
Sourcefn collect_binds<'b>(
&'b self,
out: &mut DB::BindCollector<'b>,
metadata_lookup: &mut DB::MetadataLookup,
backend: &'b DB,
) -> QueryResult<()>
fn collect_binds<'b>( &'b self, out: &mut DB::BindCollector<'b>, metadata_lookup: &mut DB::MetadataLookup, backend: &'b DB, ) -> QueryResult<()>
Serializes all bind parameters in this query.
A bind parameter is a value which is sent separately from the query
itself. It is represented in SQL with a placeholder such as ? or $1.
This method should only be called by implementations of Connection.
Sourcefn is_safe_to_cache_prepared(&self, backend: &DB) -> QueryResult<bool>
fn is_safe_to_cache_prepared(&self, backend: &DB) -> QueryResult<bool>
Is this query safe to store in the prepared statement cache?
In order to keep our prepared statement cache at a reasonable size, we
avoid caching any queries which represent a potentially unbounded number
of SQL queries. Generally this will only return true for queries for
which to_sql will always construct exactly identical SQL.
Some examples of where this method will return false are:
SqlLiteral(We don’t know if the SQL was constructed dynamically, so we must assume that it was)InandNotIn(Each value requires a separate bind param placeholder)
This method should only be called by implementations of Connection.
Sourcefn is_noop(&self, backend: &DB) -> QueryResult<bool>
fn is_noop(&self, backend: &DB) -> QueryResult<bool>
Does walking this AST have any effect?
Trait Implementations§
Source§impl<DB> QueryId for dyn QueryFragment<DB>
impl<DB> QueryId for dyn QueryFragment<DB>
Source§const HAS_STATIC_QUERY_ID: bool = false
const HAS_STATIC_QUERY_ID: bool = false
Self be uniquely identified by its type? Read moreDyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<DB: Backend> QueryFragment<DB> for ()
impl<DB: Backend> QueryFragment<DB> for ()
Source§impl<T, DB> QueryFragment<DB> for &T
impl<T, DB> QueryFragment<DB> for &T
Source§impl<T, DB> QueryFragment<DB> for Arc<T>
impl<T, DB> QueryFragment<DB> for Arc<T>
Source§impl<T, DB> QueryFragment<DB> for Box<T>
impl<T, DB> QueryFragment<DB> for Box<T>
Source§impl<T, DB> QueryFragment<DB> for Option<T>where
DB: Backend,
T: QueryFragment<DB>,
impl<T, DB> QueryFragment<DB> for Option<T>where
DB: Backend,
T: QueryFragment<DB>,
Source§impl<T, DB> QueryFragment<DB> for Rc<T>
impl<T, DB> QueryFragment<DB> for Rc<T>
Implementors§
impl QueryFragment<Mysql> for BoxedLimitOffsetClause<'_, Mysql>
mysql_backend only.impl QueryFragment<Mysql> for InsertOrIgnore
mysql_backend only.impl QueryFragment<Mysql> for LimitOffsetClause<NoLimitClause, NoOffsetClause>
mysql_backend only.impl QueryFragment<Mysql> for Replace
mysql_backend only.impl QueryFragment<Pg> for BoxedLimitOffsetClause<'_, Pg>
postgres_backend only.impl QueryFragment<Pg> for C
postgres_backend only.impl QueryFragment<Pg> for Posix
postgres_backend only.impl QueryFragment<Sqlite> for Binary
__sqlite-shared only.impl QueryFragment<Sqlite> for BoxedLimitOffsetClause<'_, Sqlite>
__sqlite-shared only.impl QueryFragment<Sqlite> for InsertOrIgnore
__sqlite-shared only.impl QueryFragment<Sqlite> for LimitOffsetClause<NoLimitClause, NoOffsetClause>
__sqlite-shared only.impl QueryFragment<Sqlite> for NoCase
__sqlite-shared only.impl QueryFragment<Sqlite> for RTrim
__sqlite-shared only.impl QueryFragment<Sqlite> for Replace
__sqlite-shared only.impl<'a, ST, QS, DB, GB> QueryFragment<DB, AnsiSqlSelectStatement> for BoxedSelectStatement<'a, ST, QS, DB, GB>where
DB: Backend<SelectStatementSyntax = AnsiSqlSelectStatement> + DieselReserveSpecialization,
QS: QueryFragment<DB>,
BoxedLimitOffsetClause<'a, DB>: QueryFragment<DB>,
impl<C> QueryFragment<Pg> for TransactionBuilder<'_, C>
postgres_backend only.impl<DB, Inner> QueryFragment<DB> for SqlQuery<Inner>
impl<DB, Query> QueryFragment<DB> for BoxedSqlQuery<'_, DB, Query>
impl<DB, T> QueryFragment<DB> for CollectedQuery<T>where
DB: Backend + DieselReserveSpecialization,
for<'a> <DB as Backend>::BindCollector<'a>: MoveableBindCollector<DB, BindData = T>,
impl<DB: Backend> QueryFragment<DB> for Custom
impl<DB: Backend> QueryFragment<DB> for now
impl<DB: Backend> QueryFragment<DB> for today
impl<DB> QueryFragment<DB, AnsiSqlFromClauseSyntax> for NoFromClausewhere
DB: Backend<EmptyFromClauseSyntax = AnsiSqlFromClauseSyntax>,
impl<DB> QueryFragment<DB, FrameExclusionSupport> for ExcludeCurrentRowwhere
DB: Backend<WindowFrameExclusionSupport = FrameExclusionSupport>,
impl<DB> QueryFragment<DB, FrameExclusionSupport> for ExcludeGroupwhere
DB: Backend<WindowFrameExclusionSupport = FrameExclusionSupport>,
impl<DB> QueryFragment<DB, FrameExclusionSupport> for ExcludeNoOtherswhere
DB: Backend<WindowFrameExclusionSupport = FrameExclusionSupport>,
impl<DB> QueryFragment<DB, FrameExclusionSupport> for ExcludeTieswhere
DB: Backend<WindowFrameExclusionSupport = FrameExclusionSupport>,
impl<DB> QueryFragment<DB, IsoGroupWindowFrameUnit> for Groupswhere
DB: Backend<WindowFrameClauseGroupSupport = IsoGroupWindowFrameUnit>,
impl<DB> QueryFragment<DB> for Allwhere
DB: Backend + DieselReserveSpecialization,
impl<DB> QueryFragment<DB> for CurrentRowwhere
DB: Backend,
impl<DB> QueryFragment<DB> for Distinctwhere
DB: Backend + DieselReserveSpecialization,
impl<DB> QueryFragment<DB> for Exceptwhere
DB: Backend + DieselReserveSpecialization,
impl<DB> QueryFragment<DB> for ExcludeCurrentRow
impl<DB> QueryFragment<DB> for ExcludeGroup
impl<DB> QueryFragment<DB> for ExcludeNoOthers
impl<DB> QueryFragment<DB> for ExcludeTies
impl<DB> QueryFragment<DB> for Groups
impl<DB> QueryFragment<DB> for Intersectwhere
DB: Backend + DieselReserveSpecialization,
impl<DB> QueryFragment<DB> for NoFromClause
impl<DB> QueryFragment<DB> for NoLimitClausewhere
DB: Backend + DieselReserveSpecialization,
impl<DB> QueryFragment<DB> for NoOffsetClausewhere
DB: Backend + DieselReserveSpecialization,
impl<DB> QueryFragment<DB> for NoOrderClausewhere
DB: Backend + DieselReserveSpecialization,
impl<DB> QueryFragment<DB> for NoReturningClausewhere
DB: Backend + DieselReserveSpecialization,
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<DB> QueryFragment<DB> for OffsetFollowingwhere
DB: Backend,
impl<DB> QueryFragment<DB> for OffsetPrecedingwhere
DB: Backend,
impl<DB> QueryFragment<DB> for Rangewhere
DB: Backend,
impl<DB> QueryFragment<DB> for Rowswhere
DB: Backend,
impl<DB> QueryFragment<DB> for UnboundedFollowingwhere
DB: Backend,
impl<DB> QueryFragment<DB> for UnboundedPrecedingwhere
DB: Backend,
impl<DB> QueryFragment<DB> for Unionwhere
DB: Backend + DieselReserveSpecialization,
impl<Expr, DB> QueryFragment<DB, PgLikeReturningClause> for ReturningClause<Expr>
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<Expr, DB> QueryFragment<DB> for LimitClause<Expr>
impl<Expr, DB> QueryFragment<DB> for OffsetClause<Expr>
impl<Expr, DB> QueryFragment<DB> for OrderClause<Expr>
impl<Expr, DB> QueryFragment<DB> for ReturningClause<Expr>
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<F, S, D, W, O, LOf, G, H, LC, DB> QueryFragment<DB, AnsiSqlSelectStatement> for SelectStatement<F, S, D, W, O, LOf, G, H, LC>where
DB: Backend<SelectStatementSyntax = AnsiSqlSelectStatement>,
S: QueryFragment<DB>,
F: QueryFragment<DB>,
D: QueryFragment<DB>,
W: QueryFragment<DB>,
O: QueryFragment<DB>,
LOf: QueryFragment<DB>,
G: QueryFragment<DB>,
H: QueryFragment<DB>,
LC: QueryFragment<DB>,
impl<F, S, D, W, O, LOf, G, H, LC, DB> QueryFragment<DB> for SelectStatement<F, S, D, W, O, LOf, G, H, LC>
impl<L, O> QueryFragment<Mysql> for LimitOffsetClause<LimitClause<L>, OffsetClause<O>>
mysql_backend only.impl<L, O> QueryFragment<Pg> for LimitOffsetClause<L, O>
postgres_backend only.impl<L, O> QueryFragment<Sqlite> for LimitOffsetClause<LimitClause<L>, OffsetClause<O>>
__sqlite-shared only.impl<L, R, DB> QueryFragment<DB, ConcatWithPipesClause> for Concat<L, R>where
L: QueryFragment<DB>,
R: QueryFragment<DB>,
DB: Backend + SqlDialect<ConcatClause = ConcatWithPipesClause>,
impl<L, R, DB> QueryFragment<DB> for Concat<L, R>
impl<L> QueryFragment<Mysql> for LimitOffsetClause<LimitClause<L>, NoOffsetClause>
mysql_backend only.impl<L> QueryFragment<Sqlite> for LimitOffsetClause<LimitClause<L>, NoOffsetClause>
__sqlite-shared only.impl<O> QueryFragment<Sqlite> for LimitOffsetClause<NoLimitClause, OffsetClause<O>>
__sqlite-shared only.impl<Query, Value, DB> QueryFragment<DB> for UncheckedBind<Query, Value>
impl<S, C, DB> QueryFragment<DB> for AliasedField<S, C>
impl<S, DB> QueryFragment<DB, AsAliasSyntax> for Alias<S>
impl<S, DB> QueryFragment<DB> for Alias<S>
impl<S, TSM> QueryFragment<Pg> for Tablesample<S, TSM>where
S: QueryFragment<Pg>,
TSM: TablesampleMethod,
postgres_backend only.impl<S> QueryFragment<Pg> for Only<S>where
S: QueryFragment<Pg>,
postgres_backend only.impl<ST, I, DB> QueryFragment<DB, AnsiSqlArrayComparison> for Many<ST, I>where
DB: Backend + HasSqlType<ST> + SqlDialect<ArrayComparison = AnsiSqlArrayComparison>,
ST: SingleValue,
I: ToSql<ST, DB>,
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<ST, I, DB> QueryFragment<DB> for Many<ST, I>
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<ST, QS, DB, GB> QueryFragment<DB> for BoxedSelectStatement<'_, ST, QS, DB, GB>
impl<ST, T, DB> QueryFragment<DB> for SqlLiteral<ST, T>where
DB: Backend,
T: QueryFragment<DB>,
impl<T, C, DB> QueryFragment<DB> for Collate<T, C>
impl<T, DB> QueryFragment<DB, AnsiSqlExistsSyntax> for Exists<T>
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<T, DB> QueryFragment<DB> for Exists<T>
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<T, Tab, DB> QueryFragment<DB> for ValuesClause<T, Tab>
impl<T, U, DB> QueryFragment<DB, AnsiSqlArrayComparison> for In<T, U>where
DB: Backend + SqlDialect<ArrayComparison = AnsiSqlArrayComparison>,
T: QueryFragment<DB>,
U: QueryFragment<DB> + InExpression,
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<T, U, DB> QueryFragment<DB, AnsiSqlArrayComparison> for NotIn<T, U>where
DB: Backend + SqlDialect<ArrayComparison = AnsiSqlArrayComparison>,
T: QueryFragment<DB>,
U: QueryFragment<DB> + InExpression,
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<T, U, DB> QueryFragment<DB> for In<T, U>
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<T, U, DB> QueryFragment<DB> for NotIn<T, U>
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.impl<T, U, Op, Ret, DB> QueryFragment<DB> for InsertStatement<T, U, Op, Ret>where
DB: Backend + DieselReserveSpecialization,
T: Table,
T::FromClause: QueryFragment<DB>,
U: QueryFragment<DB> + CanInsertInSingleQuery<DB>,
Op: QueryFragment<DB>,
Ret: QueryFragment<DB>,
impl<T, U, Ret, DB> QueryFragment<DB> for DeleteStatement<T, U, Ret>where
DB: Backend + DieselReserveSpecialization,
T: Table,
FromClause<T>: QueryFragment<DB>,
U: QueryFragment<DB>,
Ret: QueryFragment<DB>,
impl<T, U, V, Ret, DB> QueryFragment<DB> for UpdateStatement<T, U, V, Ret>where
DB: Backend + DieselReserveSpecialization,
T: Table,
T::FromClause: QueryFragment<DB>,
U: QueryFragment<DB>,
V: QueryFragment<DB>,
Ret: QueryFragment<DB>,
impl<T: QueryFragment<Mysql>> QueryFragment<Mysql> for ParenthesisWrapper<T>
mysql_backend only.impl<T: QueryFragment<Pg>> QueryFragment<Pg> for ParenthesisWrapper<T>
postgres_backend only.impl<T: QueryFragment<Sqlite>> QueryFragment<Sqlite> for ParenthesisWrapper<T>
__sqlite-shared only.impl<T> QueryFragment<Pg> for DistinctOnClause<T>where
T: QueryFragment<Pg>,
postgres_backend only.