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)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>
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 more