pub struct WithQuery { /* private fields */ }Expand description
A WITH query. A simple SQL query that has a WITH clause (WithClause).
The WithClause can contain one or multiple common table expressions (CommonTableExpression).
These named queries can act as a โquery local tableโ that are materialized during execution and then can be used by the query prefixed with the WITH clause.
A WITH clause can contain multiple of these CommonTableExpression. (Except in the case of recursive WITH query which can only contain one CommonTableExpression).
A CommonTableExpression is a name, column names and a query returning data for those columns.
Some databases (like sqlite) restrict the acceptable kinds of queries inside of the WITH clause common table expressions. These databases only allow SelectStatements to form a common table expression.
Other databases like postgres allow modification queries (UPDATE, DELETE) inside of the WITH clause but they have to return a table. (They must have a RETURNING clause).
sea-query doesnโt check this or restrict the kind of CommonTableExpression that you can create in rust. This means that you can put an UPDATE or DELETE queries into WITH clause and sea-query will succeed in generating that kind of sql query but the execution inside the database will fail because they are invalid.
It is your responsibility to ensure that the kind of WITH clause that you put together makes sense and valid for that database that you are using.
NOTE that for recursive WITH queries (in sql: โWITH RECURSIVEโ) you can only have a single CommonTableExpression inside of the WITH clause. That query must match certain requirements:
- It is a query of UNION or UNION ALL of two queries.
- The first part of the query (the left side of the UNION) must be executable first in itself. It must be non-recursive. (Cannot contain self reference)
- The self reference must appear in the right hand side of the UNION.
- The query can only have a single self-reference.
- Recursive data-modifying statements are not supported, but you can use the results of a recursive SELECT query in a data-modifying statement. (like so: WITH RECURSIVE cte_name(a,b,c,d) AS (SELECT โฆ UNION SELECT โฆ FROM โฆ JOIN cte_name ON โฆ WHERE โฆ) DELETE FROM table WHERE table.a = cte_name.a)
It is mandatory to set the Self::cte and the Self::query.
Implementationsยง
Sourceยงimpl WithQuery
impl WithQuery
Sourcepub fn with_clause(&mut self, with_clause: WithClause) -> &mut Self
pub fn with_clause(&mut self, with_clause: WithClause) -> &mut Self
Set the whole WithClause.
Sourcepub fn recursive(&mut self, recursive: bool) -> &mut Self
pub fn recursive(&mut self, recursive: bool) -> &mut Self
Set the WithClause::recursive. See that method for more information.
Sourcepub fn search(&mut self, search: Search) -> &mut Self
pub fn search(&mut self, search: Search) -> &mut Self
Add the WithClause::search. See that method for more information.
Sourcepub fn cycle(&mut self, cycle: Cycle) -> &mut Self
pub fn cycle(&mut self, cycle: Cycle) -> &mut Self
Set the WithClause::cycle. See that method for more information.
Sourcepub fn cte(&mut self, cte: CommonTableExpression) -> &mut Self
pub fn cte(&mut self, cte: CommonTableExpression) -> &mut Self
Add a CommonTableExpression to the with clause. See WithClause::cte.
Sourcepub fn query<T>(&mut self, query: T) -> &mut Selfwhere
T: Into<SubQueryStatement>,
pub fn query<T>(&mut self, query: T) -> &mut Selfwhere
T: Into<SubQueryStatement>,
Set the query that you execute with the WithClause.
Sourceยงimpl WithQuery
impl WithQuery
Sourcepub fn build_collect_into<T: QueryBuilder>(
&self,
query_builder: T,
sql: &mut impl SqlWriter,
)
pub fn build_collect_into<T: QueryBuilder>( &self, query_builder: T, sql: &mut impl SqlWriter, )
Sourcepub fn build_collect<T: QueryBuilder>(
&self,
query_builder: T,
sql: &mut impl SqlWriter,
) -> String
pub fn build_collect<T: QueryBuilder>( &self, query_builder: T, sql: &mut impl SqlWriter, ) -> String
Sourcepub fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
pub fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
Sourcepub fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
pub fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
Trait Implementationsยง
Sourceยงimpl AuditTrait for WithQuery
Available on crate feature audit only.
impl AuditTrait for WithQuery
audit only.fn audit(&self) -> Result<QueryAccessAudit, Error>
Sourceยงfn audit_unwrap(&self) -> QueryAccessAudit
fn audit_unwrap(&self) -> QueryAccessAudit
audit().unwrap()Sourceยงimpl From<WithQuery> for SubQueryStatement
impl From<WithQuery> for SubQueryStatement
Sourceยงimpl QueryStatementBuilder for WithQuery
impl QueryStatementBuilder for WithQuery
Sourceยงfn build_collect_any_into(
&self,
query_builder: &impl QueryBuilder,
sql: &mut impl SqlWriter,
)
fn build_collect_any_into( &self, query_builder: &impl QueryBuilder, sql: &mut impl SqlWriter, )
Sourceยงfn build_any(&self, query_builder: &impl QueryBuilder) -> (String, Values)
fn build_any(&self, query_builder: &impl QueryBuilder) -> (String, Values)
Sourceยงfn build_collect_any(
&self,
query_builder: &impl QueryBuilder,
sql: &mut impl SqlWriter,
) -> String
fn build_collect_any( &self, query_builder: &impl QueryBuilder, sql: &mut impl SqlWriter, ) -> String
fn into_sub_query_statement(self) -> SubQueryStatement
Sourceยงimpl QueryStatementWriter for WithQuery
impl QueryStatementWriter for WithQuery
fn build_collect_into<T: QueryBuilder>( &self, query_builder: T, sql: &mut impl SqlWriter, )
Sourceยงfn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
Sourceยงfn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
Sourceยงfn build_collect<T: QueryBuilder>(
&self,
query_builder: T,
sql: &mut impl SqlWriter,
) -> String
fn build_collect<T: QueryBuilder>( &self, query_builder: T, sql: &mut impl SqlWriter, ) -> String
impl StructuralPartialEq for WithQuery
Auto Trait Implementationsยง
impl Freeze for WithQuery
impl RefUnwindSafe for WithQuery
impl Send for WithQuery
impl Sync for WithQuery
impl Unpin for WithQuery
impl UnwindSafe for WithQuery
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T> ExprTrait for T
impl<T> ExprTrait for T
Sourceยงfn as_enum<N>(self, type_name: N) -> Exprwhere
N: IntoIden,
fn as_enum<N>(self, type_name: N) -> Exprwhere
N: IntoIden,
AS enum expression. Read moreSourceยงfn cast_as<N>(self, type_name: N) -> Exprwhere
N: IntoIden,
fn cast_as<N>(self, type_name: N) -> Exprwhere
N: IntoIden,
CAST AS expression. Read moreSourceยงfn equals<C>(self, col: C) -> Exprwhere
C: IntoColumnRef,
fn equals<C>(self, col: C) -> Exprwhere
C: IntoColumnRef,
Sourceยงfn in_subquery(self, sel: SelectStatement) -> Expr
fn in_subquery(self, sel: SelectStatement) -> Expr
IN sub-query expression. Read moreSourceยงfn in_tuples<V, I>(self, v: I) -> Exprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
fn in_tuples<V, I>(self, v: I) -> Exprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
IN sub expression. Read moreSourceยงfn is_not_null(self) -> Expr
fn is_not_null(self) -> Expr
IS NOT NULL expression. Read moreSourceยงfn left_shift<R>(self, right: R) -> Expr
fn left_shift<R>(self, right: R) -> Expr
Sourceยงfn not_between<A, B>(self, a: A, b: B) -> Expr
fn not_between<A, B>(self, a: A, b: B) -> Expr
NOT BETWEEN expression. Read moreSourceยงfn not_equals<C>(self, col: C) -> Exprwhere
C: IntoColumnRef,
fn not_equals<C>(self, col: C) -> Exprwhere
C: IntoColumnRef,
Sourceยงfn not_in_subquery(self, sel: SelectStatement) -> Expr
fn not_in_subquery(self, sel: SelectStatement) -> Expr
NOT IN sub-query expression. Read moreSourceยงfn not_like<L>(self, like: L) -> Exprwhere
L: IntoLikeExpr,
fn not_like<L>(self, like: L) -> Exprwhere
L: IntoLikeExpr,
NOT LIKE expression. Read moreSourceยงfn right_shift<R>(self, right: R) -> Expr
fn right_shift<R>(self, right: R) -> Expr
Sourceยงimpl<T> PgExpr for Twhere
T: ExprTrait,
impl<T> PgExpr for Twhere
T: ExprTrait,
Sourceยงfn concatenate<T>(self, right: T) -> Expr
fn concatenate<T>(self, right: T) -> Expr
backend-postgres only.||) expression. Read moreSourceยงfn concat<T>(self, right: T) -> Expr
fn concat<T>(self, right: T) -> Expr
backend-postgres only.PgExpr::concatenateSourceยงfn matches<T>(self, expr: T) -> Expr
fn matches<T>(self, expr: T) -> Expr
backend-postgres only.@@) expression. Read moreSourceยงfn contains<T>(self, expr: T) -> Expr
fn contains<T>(self, expr: T) -> Expr
backend-postgres only.@>) expression. Read moreSourceยงfn contained<T>(self, expr: T) -> Expr
fn contained<T>(self, expr: T) -> Expr
backend-postgres only.<@) expression. Read moreSourceยงfn ilike<L>(self, like: L) -> Exprwhere
L: IntoLikeExpr,
fn ilike<L>(self, like: L) -> Exprwhere
L: IntoLikeExpr,
backend-postgres only.ILIKE expression. Read moreSourceยงfn not_ilike<L>(self, like: L) -> Exprwhere
L: IntoLikeExpr,
fn not_ilike<L>(self, like: L) -> Exprwhere
L: IntoLikeExpr,
backend-postgres only.NOT ILIKE expressionSourceยงfn get_json_field<T>(self, right: T) -> Expr
fn get_json_field<T>(self, right: T) -> Expr
backend-postgres only.->). Read moreSourceยงimpl<T> SqliteExpr for Twhere
T: ExprTrait,
impl<T> SqliteExpr for Twhere
T: ExprTrait,
Sourceยงfn glob<T>(self, right: T) -> Expr
fn glob<T>(self, right: T) -> Expr
backend-sqlite only.GLOB operator. Read moreSourceยงfn matches<T>(self, right: T) -> Expr
fn matches<T>(self, right: T) -> Expr
backend-sqlite only.MATCH operator. Read moreSourceยงfn get_json_field<T>(self, right: T) -> Expr
fn get_json_field<T>(self, right: T) -> Expr
backend-sqlite only.->). Read more