pub struct Wrapper {
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
sourceimpl Wrapper
impl Wrapper
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: Wrapper) -> Self
pub fn push_wrapper(self, arg: Wrapper) -> 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<'s, F>(self, test: bool, method: F) -> Self where
F: FnOnce(Self) -> Self,
pub fn do_if<'s, F>(self, test: bool, method: F) -> Self where
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<'s, F>(self, test: bool, method: F) -> Self where
F: FnOnce(Self) -> Self,
pub fn if<'s, F>(self, test: bool, method: F) -> Self where
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<'s, F>(
self,
test: bool,
method_if: F,
method_else: fn(_: Self) -> Self
) -> Self where
F: FnOnce(Self) -> Self,
pub fn do_if_else<'s, F>(
self,
test: bool,
method_if: F,
method_else: fn(_: Self) -> Self
) -> Self where
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<'s, F>(
self,
test: bool,
method_if: F,
method_else: fn(_: Self) -> Self
) -> Self where
F: FnOnce(Self) -> Self,
pub fn if_else<'s, F>(
self,
test: bool,
method_if: F,
method_else: fn(_: Self) -> Self
) -> Self where
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<'s, F>(
self,
cases: &[(bool, fn(_: Wrapper) -> Wrapper)],
default: F
) -> Self where
F: FnOnce(Self) -> Self,
pub fn do_match<'s, F>(
self,
cases: &[(bool, fn(_: Wrapper) -> Wrapper)],
default: F
) -> Self where
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]) -> Self where
T: Serialize,
pub fn push_arg<T>(self, arg: T) -> Self where
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) -> Self where
T: Serialize,
pub fn all_eq<T>(self, arg: T) -> Self where
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) -> Self where
T: Serialize,
pub fn eq<T>(self, column: &str, obj: T) -> Self where
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) -> Self where
T: Serialize,
pub fn not_between<T>(self, column: &str, min: T, max: T) -> Self where
T: Serialize,
pub fn like<T>(self, column: &str, obj: T) -> Self where
T: Serialize,
pub fn like_left<T>(self, column: &str, obj: T) -> Self where
T: Serialize,
pub fn like_right<T>(self, column: &str, obj: T) -> Self where
T: Serialize,
pub fn not_like<T>(self, column: &str, obj: T) -> Self where
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]) -> Self where
T: Serialize,
pub fn in_array<T>(self, column: &str, obj: &[T]) -> Self where
T: Serialize,
gen sql: * in (,,*)
pub fn not_in<T>(self, column: &str, obj: &[T]) -> Self where
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
Auto Trait Implementations
impl RefUnwindSafe for Wrapper
impl Send for Wrapper
impl Sync for Wrapper
impl Unpin for Wrapper
impl UnwindSafe for Wrapper
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> 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