Trait diesel::query_builder::QueryFragment
source · [−]pub trait QueryFragment<DB: Backend> {
fn walk_ast(&self, pass: AstPass<'_, DB>) -> QueryResult<()>;
fn to_sql(&self, out: &mut DB::QueryBuilder) -> QueryResult<()> { ... }
fn collect_binds(
&self,
out: &mut DB::BindCollector,
metadata_lookup: &DB::MetadataLookup
) -> QueryResult<()> { ... }
fn is_safe_to_cache_prepared(&self) -> 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
fn to_sql(&self, out: &mut DB::QueryBuilder) -> QueryResult<()>
fn to_sql(&self, out: &mut DB::QueryBuilder) -> QueryResult<()>
Converts this QueryFragment
to its SQL representation.
This method should only be called by implementations of Connection
.
fn collect_binds(
&self,
out: &mut DB::BindCollector,
metadata_lookup: &DB::MetadataLookup
) -> QueryResult<()>
fn collect_binds(
&self,
out: &mut DB::BindCollector,
metadata_lookup: &DB::MetadataLookup
) -> 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
.
fn is_safe_to_cache_prepared(&self) -> QueryResult<bool>
fn is_safe_to_cache_prepared(&self) -> 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)In
andNotIn
(Each value requires a separate bind param placeholder)
This method should only be called by implementations of Connection
.
Trait Implementations
sourceimpl<DB> QueryId for dyn QueryFragment<DB>
impl<DB> QueryId for dyn QueryFragment<DB>
sourceconst HAS_STATIC_QUERY_ID: bool
const HAS_STATIC_QUERY_ID: bool
Can the SQL generated by Self
be uniquely identified by its type? Read more