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

pub struct Wrapper {
    pub driver_type: DriverType,
    pub dml: String,
    pub sql: String,
    pub args: Vec<Bson>,
    pub formats: HashMap<String, fn(arg: &str) -> 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: DriverTypedml: Stringsql: Stringargs: Vec<Bson>formats: HashMap<String, fn(arg: &str) -> String>

Implementations

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

push sql,args into self

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

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

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

link wrapper sql, if end with where , do nothing

link wrapper sql, if end with where , do nothing

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

format column

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

not equal

sql: column > obj

sql: column >= obj

sql: column < obj

sql: column <= obj

gen sql: * in (,,*)

gen sql: * in (,,*)

gen sql: * in (,,*)

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.