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 WithQuery
pub fn with_clause(&mut self, with_clause: WithClause) -> &mut WithQuery
Set the whole WithClause.
Sourcepub fn recursive(&mut self, recursive: bool) -> &mut WithQuery
pub fn recursive(&mut self, recursive: bool) -> &mut WithQuery
Set the WithClause::recursive. See that method for more information.
Sourcepub fn search(&mut self, search: Search) -> &mut WithQuery
pub fn search(&mut self, search: Search) -> &mut WithQuery
Add the WithClause::search. See that method for more information.
Sourcepub fn cycle(&mut self, cycle: Cycle) -> &mut WithQuery
pub fn cycle(&mut self, cycle: Cycle) -> &mut WithQuery
Set the WithClause::cycle. See that method for more information.
Sourcepub fn cte(&mut self, cte: CommonTableExpression) -> &mut WithQuery
pub fn cte(&mut self, cte: CommonTableExpression) -> &mut WithQuery
Add a CommonTableExpression to the with clause. See WithClause::cte.
Sourcepub fn query<T>(&mut self, query: T) -> &mut WithQuerywhere
T: QueryStatementBuilder,
pub fn query<T>(&mut self, query: T) -> &mut WithQuerywhere
T: QueryStatementBuilder,
Set the query that you execute with the WithClause.
Source§impl WithQuery
impl WithQuery
Sourcepub fn build_collect_into<T>(&self, query_builder: T, sql: &mut dyn SqlWriter)where
T: QueryBuilder,
pub fn build_collect_into<T>(&self, query_builder: T, sql: &mut dyn SqlWriter)where
T: QueryBuilder,
Sourcepub fn build_collect<T>(
&self,
query_builder: T,
sql: &mut dyn SqlWriter,
) -> Stringwhere
T: QueryBuilder,
pub fn build_collect<T>(
&self,
query_builder: T,
sql: &mut dyn SqlWriter,
) -> Stringwhere
T: QueryBuilder,
Sourcepub fn build<T>(&self, query_builder: T) -> (String, Values)where
T: QueryBuilder,
pub fn build<T>(&self, query_builder: T) -> (String, Values)where
T: QueryBuilder,
Sourcepub fn to_string<T>(&self, query_builder: T) -> Stringwhere
T: QueryBuilder,
pub fn to_string<T>(&self, query_builder: T) -> Stringwhere
T: QueryBuilder,
Trait Implementations§
Source§impl QueryStatementBuilder for WithQuery
impl QueryStatementBuilder for WithQuery
Source§fn build_collect_any_into(
&self,
query_builder: &dyn QueryBuilder,
sql: &mut dyn SqlWriter,
)
fn build_collect_any_into( &self, query_builder: &dyn QueryBuilder, sql: &mut dyn SqlWriter, )
fn into_sub_query_statement(self) -> SubQueryStatement
Source§fn build_any(&self, query_builder: &dyn QueryBuilder) -> (String, Values)
fn build_any(&self, query_builder: &dyn QueryBuilder) -> (String, Values)
Source§fn build_collect_any(
&self,
query_builder: &dyn QueryBuilder,
sql: &mut dyn SqlWriter,
) -> String
fn build_collect_any( &self, query_builder: &dyn QueryBuilder, sql: &mut dyn SqlWriter, ) -> String
Source§impl QueryStatementWriter for WithQuery
impl QueryStatementWriter for WithQuery
fn build_collect_into<T>(&self, query_builder: T, sql: &mut dyn SqlWriter)where
T: QueryBuilder,
Source§fn to_string<T>(&self, query_builder: T) -> Stringwhere
T: QueryBuilder,
fn to_string<T>(&self, query_builder: T) -> Stringwhere
T: QueryBuilder,
Source§fn build<T>(&self, query_builder: T) -> (String, Values)where
T: QueryBuilder,
fn build<T>(&self, query_builder: T) -> (String, Values)where
T: QueryBuilder,
Source§fn build_collect<T>(&self, query_builder: T, sql: &mut dyn SqlWriter) -> Stringwhere
T: QueryBuilder,
fn build_collect<T>(&self, query_builder: T, sql: &mut dyn SqlWriter) -> Stringwhere
T: QueryBuilder,
Source§impl SqlxBinder for WithQuery
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)
Source§impl StatementBuilder for WithQuery
impl StatementBuilder for WithQuery
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);