pub struct Resolver<'a> { /* private fields */ }
Expand description
The resolver may hold values for placeholder tokens from SqlExpr and replace those.
It will replace placeholder tokens from SqlExpr with concret values as good as it can.
This is a typical use:
use toql_core::{sql_expr::SqlExpr, alias_format::AliasFormat};
use toql_core::{alias_translator::AliasTranslator, sql_expr::resolver::Resolver};
let sql_expr = SqlExpr::self_alias();
let mut alias_translator = AliasTranslator::new(AliasFormat::TinyIndex);
let resolver = Resolver::new().with_self_alias("t1");
let sql = resolver.to_sql(&sql_expr, &mut alias_translator).unwrap();
assert_eq!("t1", sql.to_unsafe_string());
Implementations
sourceimpl<'a> Resolver<'a>
impl<'a> Resolver<'a>
pub fn new() -> Self
sourcepub fn with_self_alias(self, alias: &'a str) -> Self
pub fn with_self_alias(self, alias: &'a str) -> Self
Replace self alias placeholders with this alias.
sourcepub fn with_other_alias(self, alias: &'a str) -> Self
pub fn with_other_alias(self, alias: &'a str) -> Self
Replace other alias placeholders with this alias.
sourcepub fn with_aux_params(self, aux_params: &'a ParameterMap<'a>) -> Self
pub fn with_aux_params(self, aux_params: &'a ParameterMap<'a>) -> Self
Replace aux param placeholders with values from this map.
sourcepub fn with_arguments(self, arguments: &'a [SqlArg]) -> Self
pub fn with_arguments(self, arguments: &'a [SqlArg]) -> Self
Replace argument placeholder with values from this argument list.
sourcepub fn replace_aux_params(
sql_expr: SqlExpr,
aux_params_exprs: &HashMap<String, SqlExpr>
) -> SqlExpr
pub fn replace_aux_params(
sql_expr: SqlExpr,
aux_params_exprs: &HashMap<String, SqlExpr>
) -> SqlExpr
Replace aux param palceholders with SQL expressions. Skips placeholders that can’t be replaced.
sourcepub fn resolve_aux_params(
sql_expr: SqlExpr,
aux_params: &ParameterMap<'_>
) -> SqlExpr
pub fn resolve_aux_params(
sql_expr: SqlExpr,
aux_params: &ParameterMap<'_>
) -> SqlExpr
Resolve aux params placeholders with value from parameter map. Skips placeholders that cannot be resolved.
pub fn resolve(&self, sql_expr: &'a SqlExpr) -> Result<SqlExpr, ResolverError>
sourcepub fn alias_to_literals(
&self,
sql_expr: &'a SqlExpr
) -> Result<SqlExpr, ResolverError>
pub fn alias_to_literals(
&self,
sql_expr: &'a SqlExpr
) -> Result<SqlExpr, ResolverError>
Resolve all aliases to literal strings.
sourcepub fn to_sql(
&self,
sql_expr: &SqlExpr,
alias_translator: &mut AliasTranslator
) -> Result<Sql, ResolverError>
pub fn to_sql(
&self,
sql_expr: &SqlExpr,
alias_translator: &mut AliasTranslator
) -> Result<Sql, ResolverError>
Resolve all placeholder tokens and translate aliases with the AliasTranslator. This turns an SqlExpr into Sql, if all placeholder tokens can be resolved and fail otherwise.
pub fn token_to_sql(
token: &SqlExprToken,
alias_translator: &mut AliasTranslator,
stmt: &mut String,
args: &mut Vec<SqlArg>
) -> Result<(), ResolverError>
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Resolver<'a>
impl<'a> Send for Resolver<'a>
impl<'a> Sync for Resolver<'a>
impl<'a> Unpin for Resolver<'a>
impl<'a> UnwindSafe for Resolver<'a>
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> 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