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

Walk over this QueryFragment for all passes.

This method is where the actual behavior of an AST node is implemented. This method will contain the behavior required for all possible AST passes. See AstPass for more details.

Provided methods

Converts this QueryFragment to its SQL representation.

This method should only be called by implementations of Connection.

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.

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 and NotIn (Each value requires a separate bind param placeholder)

This method should only be called by implementations of Connection.

Trait Implementations

A type which uniquely represents Self in a SQL query. Read more

Can the SQL generated by Self be uniquely identified by its type? Read more

Returns the type id of Self::QueryId if Self::HAS_STATIC_QUERY_ID. Returns None otherwise. Read more

Implementations on Foreign Types

Implementors