Trait diesel::query_builder::QueryFragment
source · 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 as HasBindCollector<'b>>::BindCollector,
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<()>
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.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 as HasBindCollector<'b>>::BindCollector,
metadata_lookup: &mut DB::MetadataLookup,
backend: &'b DB
) -> QueryResult<()>
fn collect_binds<'b>( &'b self, out: &mut <DB as HasBindCollector<'b>>::BindCollector, metadata_lookup: &mut DB::MetadataLookup, backend: &'b DB ) -> QueryResult<()>
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.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>
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.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)In
andNotIn
(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>
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.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 moreImplementors§
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<DB> QueryFragment<DB, AnsiSqlFromClauseSyntax> for NoFromClausewhere DB: Backend<EmptyFromClauseSyntax = AnsiSqlFromClauseSyntax>,
impl<Expr, DB> QueryFragment<DB, PgLikeReturningClause> for ReturningClause<Expr>where DB: Backend<ReturningClause = PgLikeReturningClause>, Expr: QueryFragment<DB>,
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<L, R, DB> QueryFragment<DB, ConcatWithPipesClause> for Concat<L, R>where L: QueryFragment<DB>, R: QueryFragment<DB>, DB: Backend + SqlDialect<ConcatClause = ConcatWithPipesClause>,
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<T, DB> QueryFragment<DB, AnsiSqlExistsSyntax> for Exists<T>where DB: Backend + SqlDialect<ExistsSyntax = AnsiSqlExistsSyntax>, T: QueryFragment<DB>,
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.impl<T, U, DB> QueryFragment<DB, AnsiSqlArrayComparison> for In<T, U>where DB: Backend + SqlDialect<ArrayComparison = AnsiSqlArrayComparison>, T: QueryFragment<DB>, U: QueryFragment<DB> + MaybeEmpty,
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> + MaybeEmpty,
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.