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§

§

impl WithQuery

pub fn new() -> WithQuery

Constructs a new empty WithQuery.

pub fn with_clause(&mut self, with_clause: WithClause) -> &mut WithQuery

Set the whole WithClause.

pub fn recursive(&mut self, recursive: bool) -> &mut WithQuery

Set the WithClause::recursive. See that method for more information.

pub fn search(&mut self, search: Search) -> &mut WithQuery

Add the WithClause::search. See that method for more information.

pub fn cycle(&mut self, cycle: Cycle) -> &mut WithQuery

Set the WithClause::cycle. See that method for more information.

pub fn cte(&mut self, cte: CommonTableExpression) -> &mut WithQuery

Add a CommonTableExpression to the with clause. See WithClause::cte.

pub fn query<T>(&mut self, query: T) -> &mut WithQuerywhere T: QueryStatementBuilder,

Set the query that you execute with the WithClause.

Trait Implementations§

§

impl Clone for WithQuery

§

fn clone(&self) -> WithQuery

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for WithQuery

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for WithQuery

§

fn default() -> WithQuery

Returns the “default value” for a type. Read more
§

impl QueryStatementBuilder for WithQuery

§

fn build_collect_any_into( &self, query_builder: &dyn QueryBuilder, sql: &mut dyn SqlWriter )

Build corresponding SQL statement into the SqlWriter for certain database backend and collect query parameters
§

fn into_sub_query_statement(self) -> SubQueryStatement

§

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
§

fn build_collect_any( &self, query_builder: &dyn QueryBuilder, sql: &mut dyn SqlWriter ) -> String

Build corresponding SQL statement for certain database backend and collect query parameters
§

impl QueryStatementWriter for WithQuery

§

fn build_collect_into<T>(&self, query_builder: T, sql: &mut dyn SqlWriter)where T: QueryBuilder,

§

fn to_string<T>(&self, query_builder: T) -> Stringwhere T: QueryBuilder,

Build corresponding SQL statement for certain database backend and return SQL string Read more
§

fn build<T>(&self, query_builder: T) -> (String, Values)where T: QueryBuilder,

Build corresponding SQL statement for certain database backend and collect query parameters into a vector Read more
§

fn build_collect<T>(&self, query_builder: T, sql: &mut dyn SqlWriter) -> Stringwhere T: QueryBuilder,

Build corresponding SQL statement for certain database backend and collect query parameters Read more
§

impl SqlxBinder for WithQuery

§

fn build_sqlx<T>(&self, query_builder: T) -> (String, SqlxValues)where T: QueryBuilder,

§

fn build_any_sqlx( &self, query_builder: &dyn QueryBuilder ) -> (String, SqlxValues)

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more