pub struct SqlExpr { /* private fields */ }
Expand description
A SQL expression is a list of tokens that can be resolved into SQL.
Library users are advised to not build it programmatically,
but to use the sql_expr!
macro.
This macro provides compile time safety and convenience.
However it’s also possible to build it programmatically:
Example
use toql_core::sql_expr::SqlExpr;
let mut e = SqlExpr::literal("SELECT ");
e.push_self_alias();
e.push_literal("id FROM User ");
e.push_self_alias();
assert_eq!("SELECT ..id FROM User ..", e.to_string());
The resolver will replace the self aliases into real aliases and build proper SQL.
Implementations
sourceimpl SqlExpr
impl SqlExpr
sourcepub fn from(tokens: Vec<SqlExprToken, Global>) -> SqlExpr
pub fn from(tokens: Vec<SqlExprToken, Global>) -> SqlExpr
Create SQL expression from token list.
sourcepub fn self_alias() -> SqlExpr
pub fn self_alias() -> SqlExpr
Create SQL expression from self alias.
sourcepub fn other_alias() -> SqlExpr
pub fn other_alias() -> SqlExpr
Create SQL expression from other alias.
sourcepub fn unresolved_arg() -> SqlExpr
pub fn unresolved_arg() -> SqlExpr
Create SQL expression from unresolved argument.
sourcepub fn aliased_column(column_name: impl Into<String>) -> SqlExpr
pub fn aliased_column(column_name: impl Into<String>) -> SqlExpr
Create SQL expression from aliased column.
sourcepub fn push_literal(&mut self, lit: impl Into<String>) -> &mut SqlExpr
pub fn push_literal(&mut self, lit: impl Into<String>) -> &mut SqlExpr
Add literal at the end of token list.
sourcepub fn pop_literals(&mut self, count: usize) -> &mut SqlExpr
pub fn pop_literals(&mut self, count: usize) -> &mut SqlExpr
Remove a number of characters -or less- from the end of the list. This affects only the last (literal) token.
sourcepub fn ends_with_literal(&self, lit: &str) -> bool
pub fn ends_with_literal(&self, lit: &str) -> bool
Return true if last literal token ends with lit
.
sourcepub fn push_self_alias(&mut self) -> &mut SqlExpr
pub fn push_self_alias(&mut self) -> &mut SqlExpr
Add self alias to the end of the list.
sourcepub fn push_other_alias(&mut self) -> &mut SqlExpr
pub fn push_other_alias(&mut self) -> &mut SqlExpr
Add other alias to the end of the list.
sourcepub fn push_alias(&mut self, alias: impl Into<String>) -> &mut SqlExpr
pub fn push_alias(&mut self, alias: impl Into<String>) -> &mut SqlExpr
Add custom alias to the end of the list.
sourcepub fn push_unresolved_arg(&mut self) -> &mut SqlExpr
pub fn push_unresolved_arg(&mut self) -> &mut SqlExpr
Add unresolved argument to the end of the list.
sourcepub fn first_aux_param(&self) -> Option<&String>
pub fn first_aux_param(&self) -> Option<&String>
Returns first auxiliary parameter, if any.
sourcepub fn push_predicate(
&mut self,
columns: Vec<PredicateColumn, Global>,
args: Vec<SqlArg, Global>
) -> &mut SqlExpr
pub fn push_predicate(
&mut self,
columns: Vec<PredicateColumn, Global>,
args: Vec<SqlArg, Global>
) -> &mut SqlExpr
Add a predicate to the end of the list.
sourcepub fn extend(&mut self, expr: impl Into<SqlExpr>) -> &mut SqlExpr
pub fn extend(&mut self, expr: impl Into<SqlExpr>) -> &mut SqlExpr
Add another SQL expression to the end of the list.
pub fn tokens(&self) -> &[SqlExprToken]
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for SqlExpr
impl Send for SqlExpr
impl Sync for SqlExpr
impl Unpin for SqlExpr
impl UnwindSafe for SqlExpr
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
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