DynamicWrapper

Struct DynamicWrapper 

Source
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

Source

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

Source

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

Source

pub fn set_formats(self, formats: HashMap<String, String>) -> Self

Source

pub fn set_dml(self, dml: &str) -> Self

Source

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

Source

pub fn push(self, sql: &str, args: Vec<Bson>) -> Self

push sql,args into self

Source

pub fn do_if<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”))

Source

pub fn if<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”))

Source

pub fn do_if_else<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)

Source

pub fn if_else<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)

Source

pub fn do_match<F>( self, cases: &[(bool, fn(DynamicWrapper) -> DynamicWrapper)], default: F, ) -> Self
where F: FnOnce(Self) -> Self,

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn pop_arg(self) -> Self

Source

pub fn not_allow_add_and_on_end(&self) -> bool

Source

pub fn and(self) -> Self

link wrapper sql, if end with where , do nothing

Source

pub fn or(self) -> Self

link wrapper sql, if end with where , do nothing

Source

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

Source

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

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

Source

pub fn do_format_column(&self, column: &str, data: &mut String)

format column

Source

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

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

Source

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

not equal

Source

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

Source

pub fn order_bys(self, column_asc: &[(&str, bool)]) -> Self

Source

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

Source

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

sql: column > obj

Source

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

sql: column >= obj

Source

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

sql: column < obj

Source

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

sql: column <= obj

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

gen sql: * in (,,*)

Source

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

gen sql: * in (,,*)

Source

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

gen sql: * in (,,*)

Source

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

Source

pub fn trim_space(self) -> Self

Source

pub fn trim_and(self) -> Self

Source

pub fn trim_or(self) -> Self

Source

pub fn trim_and_or(self) -> Self

Source

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

Source

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

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

Trait Implementations§

Source§

impl Clone for DynamicWrapper

Source§

fn clone(&self) -> DynamicWrapper

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DynamicWrapper

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more