Struct rbatis::wrapper::Wrapper[][src]

pub struct Wrapper {
    pub driver_type: DriverType,
    pub sql: String,
    pub args: Vec<Value>,
    pub formats: HashMap<String, fn(arg: &str) -> String>,
}

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: DriverTypesql: Stringargs: Vec<Value>formats: HashMap<String, fn(arg: &str) -> String>

Implementations

impl Wrapper[src]

pub fn new(driver_type: &DriverType) -> Self[src]

pub fn from(driver_type: &DriverType, sql: &str, args: Vec<Value>) -> Self[src]

pub fn trim_value(self, from: &str, to: &str) -> Self[src]

pub fn set_formats(
    self,
    formats: HashMap<String, fn(arg: &str) -> String>
) -> Self
[src]

pub fn push_wrapper(self, arg: &Wrapper) -> Self[src]

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”)]

pub fn push<T>(self, sql: &str, args: &[T]) -> Self where
    T: Serialize
[src]

push sql,args into self

pub fn do_if<'s, F>(self, test: bool, method: F) -> Self where
    F: FnOnce(Self) -> Self, 
[src]

do method,if test is true for example: let arg = 1; wrapper.do_if(true, |w| w.eq(“id”))

pub fn do_if_else<'s, F>(
    self,
    test: bool,
    method_if: F,
    method_else: fn(_: Self) -> Self
) -> Self where
    F: FnOnce(Self) -> Self, 
[src]

do method,if test is true for example: let arg = 1; wrapper.do_if(true, |w| w.eq(“id”),|w|w)

pub fn do_match<'s, F>(
    self,
    cases: &[(bool, fn(_: Wrapper) -> Wrapper)],
    default: F
) -> Self where
    F: FnOnce(Self) -> Self, 
[src]

match cases for example: let p = Option::::Some(1); let w = Wrapper::new(&DriverType::Postgres) .do_match(&[ (p == 0, |w| w.eq(“a”, “some”)), (p == 1, |w| w.eq(“a”, “some”)), ], |w| w.eq(“a”, “default”)) ;

pub fn set_sql(self, sql: &str) -> Self[src]

pub fn push_sql(self, sql: &str) -> Self[src]

pub fn set_args<T>(self, args: &[T]) -> Self where
    T: Serialize
[src]

pub fn push_arg<T>(self, arg: T) -> Self where
    T: Serialize
[src]

pub fn pop_arg(self) -> Self[src]

pub fn not_allow_add_and_on_end(&self) -> bool[src]

pub fn and(self) -> Self[src]

link wrapper sql, if end with where , do nothing

pub fn or(self) -> Self[src]

link wrapper sql, if end with where , do nothing

pub fn having(self, sql_having: &str) -> Self[src]

pub fn all_eq<T>(self, arg: T) -> Self where
    T: Serialize
[src]

arg: JsonObject or struct{} or map[String,**]

pub fn do_format_column(&self, column: &str, data: String) -> String[src]

format column

pub fn eq<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

equal for example: eq(“a”,1) “ a = 1 “

pub fn ne<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

not equal

pub fn order_by(self, is_asc: bool, columns: &[&str]) -> Self[src]

pub fn group_by(self, columns: &[&str]) -> Self[src]

pub fn gt<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

sql: column > obj

pub fn ge<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

sql: column >= obj

pub fn lt<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

sql: column < obj

pub fn le<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

sql: column <= obj

pub fn between<T>(self, column: &str, min: T, max: T) -> Self where
    T: Serialize
[src]

pub fn not_between<T>(self, column: &str, min: T, max: T) -> Self where
    T: Serialize
[src]

pub fn like<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

pub fn like_left<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

pub fn like_right<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

pub fn not_like<T>(self, column: &str, obj: T) -> Self where
    T: Serialize
[src]

pub fn is_null(self, column: &str) -> Self[src]

pub fn is_not_null(self, column: &str) -> Self[src]

pub fn in_array<T>(self, column: &str, obj: &[T]) -> Self where
    T: Serialize
[src]

gen sql: * in (,,*)

pub fn in_<T>(self, column: &str, obj: &[T]) -> Self where
    T: Serialize
[src]

gen sql: * in (,,*)

pub fn in<T>(self, column: &str, obj: &[T]) -> Self where
    T: Serialize
[src]

gen sql: * in (,,*)

pub fn not_in<T>(self, column: &str, obj: &[T]) -> Self where
    T: Serialize
[src]

pub fn trim_space(self) -> Self[src]

pub fn trim_and(self) -> Self[src]

pub fn trim_or(self) -> Self[src]

pub fn trim_and_or(self) -> Self[src]

pub fn insert_into(self, table_name: &str, columns: &str, values: &str) -> Self[src]

pub fn limit(self, limit: u64) -> Self[src]

limit for example: limit(1) “ limit 1 “

Trait Implementations

impl Clone for Wrapper[src]

impl Debug for Wrapper[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,