pub struct DynamicWrapper {
pub driver_type: DriverType,
pub dml: String,
pub sql: String,
pub args: Vec<Bson>,
pub formats: HashMap<String, String>,
}Expand description
The packing/Wrapper of the SQL SQL passed into the Wrapper keep the keyword uppercase
for Example: let w = Wrapper::new(&DriverType::Mysql) .push_sql(“id == 1”) .eq(“id”, 1) .and() .ne(“id”, 1) .and() .in_array(“id”, &[1, 2, 3]) .in_(“id”, &[1, 2, 3]) .r#in(“id”, &[1, 2, 3]) .and() .not_in(“id”, &[1, 2, 3]) .and() .like(“name”, 1) .or() .not_like(“name”, “asdf”) .and() .between(“create_time”, “2020-01-01 00:00:00”, “2020-12-12 00:00:00”) .group_by(&[“id”]) .order_by(true, &[“id”, “name”]) ;
Fields§
§driver_type: DriverType§dml: String§sql: String§args: Vec<Bson>§formats: HashMap<String, String>Implementations§
Source§impl DynamicWrapper
impl DynamicWrapper
pub fn new(driver_type: &DriverType) -> Self
pub fn trim_value(self, from: &str, to: &str) -> Self
pub fn set_formats(self, formats: HashMap<String, String>) -> Self
pub fn set_dml(self, dml: &str) -> Self
Sourcepub fn push_wrapper(self, arg: DynamicWrapper) -> Self
pub fn push_wrapper(self, arg: DynamicWrapper) -> Self
link left Wrapper to this Wrapper for Example: let w = Wrapper::new(&DriverType::Postgres).push_sql(“(”).eq(“a”, “1”).push_sql(“)”); let w2 = Wrapper::new(&DriverType::Postgres).eq(“b”, “2”) .and() .push_wrapper(w); println!(“sql:{:?}”, w2.sql.as_str()); // sql:“b = ? and (a = ?)” println!(“arg:{:?}”, w2.args.clone()); // arg:[String(“2”), String(“1”)]
Sourcepub fn do_if<F>(self, test: bool, method: F) -> Selfwhere
F: FnOnce(Self) -> Self,
pub fn do_if<F>(self, test: bool, method: F) -> Selfwhere
F: FnOnce(Self) -> Self,
do method,if test is true for example: let arg = 1; wrapper.do_if(true, |w| w.eq(“id”))
Sourcepub fn if<F>(self, test: bool, method: F) -> Selfwhere
F: FnOnce(Self) -> Self,
pub fn if<F>(self, test: bool, method: F) -> Selfwhere
F: FnOnce(Self) -> Self,
do method,if test is true for example: let arg = 1; wrapper.r#if(true, |w| w.eq(“id”))
Sourcepub fn do_if_else<F>(
self,
test: bool,
method_if: F,
method_else: fn(Self) -> Self,
) -> Selfwhere
F: FnOnce(Self) -> Self,
pub fn do_if_else<F>(
self,
test: bool,
method_if: F,
method_else: fn(Self) -> Self,
) -> Selfwhere
F: FnOnce(Self) -> Self,
do method,if test is true for example: let arg = 1; wrapper.do_if(true, |w| w.eq(“id”),|w|w)
Sourcepub fn if_else<F>(
self,
test: bool,
method_if: F,
method_else: fn(Self) -> Self,
) -> Selfwhere
F: FnOnce(Self) -> Self,
pub fn if_else<F>(
self,
test: bool,
method_if: F,
method_else: fn(Self) -> Self,
) -> Selfwhere
F: FnOnce(Self) -> Self,
do method,if test is true for example: let arg = 1; wrapper.do_if(true, |w| w.eq(“id”),|w|w)
Sourcepub fn do_match<F>(
self,
cases: &[(bool, fn(DynamicWrapper) -> DynamicWrapper)],
default: F,
) -> Selfwhere
F: FnOnce(Self) -> Self,
pub fn do_match<F>(
self,
cases: &[(bool, fn(DynamicWrapper) -> DynamicWrapper)],
default: F,
) -> Selfwhere
F: FnOnce(Self) -> Self,
match cases
for example:
let p = Option::
pub fn set_sql(self, sql: &str) -> Self
pub fn push_sql(self, sql: &str) -> Self
pub fn set_args<T>(self, args: &[T]) -> Selfwhere
T: Serialize,
pub fn push_arg<T>(self, arg: T) -> Selfwhere
T: Serialize,
pub fn pop_arg(self) -> Self
pub fn not_allow_add_and_on_end(&self) -> bool
pub fn having(self, sql_having: &str) -> Self
Sourcepub fn all_eq<T>(self, arg: T) -> Selfwhere
T: Serialize,
pub fn all_eq<T>(self, arg: T) -> Selfwhere
T: Serialize,
arg: JsonObject or struct{} or map[String,**]
Sourcepub fn do_format_column(&self, column: &str, data: &mut String)
pub fn do_format_column(&self, column: &str, data: &mut String)
format column
Sourcepub fn eq<T>(self, column: &str, obj: T) -> Selfwhere
T: Serialize,
pub fn eq<T>(self, column: &str, obj: T) -> Selfwhere
T: Serialize,
equal for example: eq(“a”,1) “ a = 1 “
pub fn order_by(self, is_asc: bool, columns: &[&str]) -> Self
pub fn order_bys(self, column_asc: &[(&str, bool)]) -> Self
pub fn group_by(self, columns: &[&str]) -> Self
pub fn between<T>(self, column: &str, min: T, max: T) -> Selfwhere
T: Serialize,
pub fn not_between<T>(self, column: &str, min: T, max: T) -> Selfwhere
T: Serialize,
pub fn like<T>(self, column: &str, obj: T) -> Selfwhere
T: Serialize,
pub fn like_left<T>(self, column: &str, obj: T) -> Selfwhere
T: Serialize,
pub fn like_right<T>(self, column: &str, obj: T) -> Selfwhere
T: Serialize,
pub fn not_like<T>(self, column: &str, obj: T) -> Selfwhere
T: Serialize,
pub fn is_null(self, column: &str) -> Self
pub fn is_not_null(self, column: &str) -> Self
Sourcepub fn in_array<T>(self, column: &str, obj: &[T]) -> Selfwhere
T: Serialize,
pub fn in_array<T>(self, column: &str, obj: &[T]) -> Selfwhere
T: Serialize,
gen sql: * in (,,*)
pub fn not_in<T>(self, column: &str, obj: &[T]) -> Selfwhere
T: Serialize,
pub fn trim_space(self) -> Self
pub fn trim_and(self) -> Self
pub fn trim_or(self) -> Self
pub fn trim_and_or(self) -> Self
pub fn insert_into(self, table_name: &str, columns: &str, values: &str) -> Self
Trait Implementations§
Source§impl Clone for DynamicWrapper
impl Clone for DynamicWrapper
Source§fn clone(&self) -> DynamicWrapper
fn clone(&self) -> DynamicWrapper
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DynamicWrapper
impl RefUnwindSafe for DynamicWrapper
impl Send for DynamicWrapper
impl Sync for DynamicWrapper
impl Unpin for DynamicWrapper
impl UnwindSafe for DynamicWrapper
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 more