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
sourceimpl 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 Self where
T: QueryStatementBuilder,
pub fn query<T>(&mut self, query: T) -> &mut Self where
T: QueryStatementBuilder,
Set the query that you execute with the WithClause.
Trait Implementations
sourceimpl QueryStatementBuilder for WithQuery
impl QueryStatementBuilder for WithQuery
sourcefn build_collect_any_into(
&self,
query_builder: &dyn QueryBuilder,
sql: &mut SqlWriter,
collector: &mut dyn FnMut(Value)
)
fn build_collect_any_into(
&self,
query_builder: &dyn QueryBuilder,
sql: &mut SqlWriter,
collector: &mut dyn FnMut(Value)
)
Build corresponding SQL statement into the SqlWriter for certain database backend and collect query parameters
fn into_sub_query_statement(self) -> SubQueryStatement
sourcefn build_any(&self, query_builder: &dyn QueryBuilder) -> (String, Values)
fn build_any(&self, query_builder: &dyn QueryBuilder) -> (String, Values)
Build corresponding SQL statement for certain database backend and collect query parameters into a vector
sourcefn build_collect_any(
&self,
query_builder: &dyn QueryBuilder,
collector: &mut dyn FnMut(Value)
) -> String
fn build_collect_any(
&self,
query_builder: &dyn QueryBuilder,
collector: &mut dyn FnMut(Value)
) -> String
Build corresponding SQL statement for certain database backend and collect query parameters
sourceimpl QueryStatementWriter for WithQuery
impl QueryStatementWriter for WithQuery
sourcefn build_collect<T: QueryBuilder>(
&self,
query_builder: T,
collector: &mut dyn FnMut(Value)
) -> String
fn build_collect<T: QueryBuilder>(
&self,
query_builder: T,
collector: &mut dyn FnMut(Value)
) -> String
Build corresponding SQL statement for certain database backend and collect query parameters Read more
sourcefn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
Build corresponding SQL statement for certain database backend and return SQL string Read more
Auto Trait Implementations
impl !RefUnwindSafe for WithQuery
impl Send for WithQuery
impl Sync for WithQuery
impl Unpin for WithQuery
impl !UnwindSafe for WithQuery
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more