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§

source

fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()>

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§

source

fn to_sql(&self, out: &mut DB::QueryBuilder, backend: &DB) -> QueryResult<()>

Available on crate feature 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.

source

fn collect_binds<'b>( &'b self, out: &mut <DB as HasBindCollector<'b>>::BindCollector, metadata_lookup: &mut DB::MetadataLookup, backend: &'b DB ) -> QueryResult<()>

Available on crate feature 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.

source

fn is_safe_to_cache_prepared(&self, backend: &DB) -> QueryResult<bool>

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

This method should only be called by implementations of Connection.

source

fn is_noop(&self, backend: &DB) -> QueryResult<bool>

Available on crate feature 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>

§

type QueryId = ()

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

const HAS_STATIC_QUERY_ID: bool = false

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

fn query_id() -> Option<TypeId>

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

Implementors§

source§

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>,

source§

impl<DB> QueryFragment<DB, AnsiSqlFromClauseSyntax> for NoFromClausewhere DB: Backend<EmptyFromClauseSyntax = AnsiSqlFromClauseSyntax>,

source§

impl<Expr, DB> QueryFragment<DB, PgLikeReturningClause> for ReturningClause<Expr>where DB: Backend<ReturningClause = PgLikeReturningClause>, Expr: QueryFragment<DB>,

source§

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>,

source§

impl<L, R, DB> QueryFragment<DB, ConcatWithPipesClause> for Concat<L, R>where L: QueryFragment<DB>, R: QueryFragment<DB>, DB: Backend + SqlDialect<ConcatClause = ConcatWithPipesClause>,

source§

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>,

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
source§

impl<T, DB> QueryFragment<DB, AnsiSqlExistsSyntax> for Exists<T>where DB: Backend + SqlDialect<ExistsSyntax = AnsiSqlExistsSyntax>, T: QueryFragment<DB>,

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
source§

impl<T, U, DB> QueryFragment<DB, AnsiSqlArrayComparison> for In<T, U>where DB: Backend + SqlDialect<ArrayComparison = AnsiSqlArrayComparison>, T: QueryFragment<DB>, U: QueryFragment<DB> + MaybeEmpty,

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
source§

impl<T, U, DB> QueryFragment<DB, AnsiSqlArrayComparison> for NotIn<T, U>where DB: Backend + SqlDialect<ArrayComparison = AnsiSqlArrayComparison>, T: QueryFragment<DB>, U: QueryFragment<DB> + MaybeEmpty,

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
source§

impl<Tab, DB, V, QId, const HAS_STATIC_QUERY_ID: bool> QueryFragment<DB, PostgresLikeBatchInsertSupport> for BatchInsert<Vec<ValuesClause<V, Tab>>, Tab, QId, HAS_STATIC_QUERY_ID>where DB: Backend + SqlDialect<BatchInsertSupport = PostgresLikeBatchInsertSupport>, DB::InsertWithDefaultKeyword: SupportsDefaultKeyword, ValuesClause<V, Tab>: QueryFragment<DB>, V: QueryFragment<DB>,