Trait dengine::Connectionable [−][src]
pub trait Connectionable { fn execute<P>(&self, sql: &str, params: P) -> Desult<()>
where
P: Clone,
Params: From<P>; fn select<T: Queryable + Debug, P: Clone>(
&self,
sql: &str,
params: P,
calc_found_rows: bool
) -> Desult<SelectHolder<T>>
where
Params: From<P>; fn value<T, R>(&self, sql: &str, colum: &str, params: R) -> Desult<T>
where
T: From<Dypes>,
R: Clone,
Params: From<R>; fn row<T, R>(&self, sql: &str, params: R) -> Desult<T>
where
T: Queryable,
R: Clone,
Params: From<R>; fn insert_update<T: Insertable>(
&self,
table: &str,
fields: Vec<T>
) -> Desult<Affected>; fn insert<T: Insertable>(
&self,
table: &str,
fields: Vec<T>
) -> Desult<Affected>; fn update<T: Insertable>(
&self,
table: &str,
fields: Vec<T>,
where_fields: HashMap<&str, Dypes>
) -> Desult<Affected>; fn delete_ids<T>(
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>,
in_out: &str
) -> Desult<Affected>
where
T: Clone,
Dypes: From<T>; fn delete_wid<T>(
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>
) -> Desult<Affected>
where
T: Clone,
Dypes: From<T>; fn delete_nwid<T>(
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>
) -> Desult<Affected>
where
T: Clone,
Dypes: From<T>; fn concat_colums(colums: Vec<&str>) -> String; fn array<T: Queryable + Debug, P: Clone>(
&self,
sql: &str,
params: P,
calc_found_rows: bool
) -> Desult<Vec<T>>
where
Params: From<P>, { ... } fn gen_dupdate(colums: Vec<String>) -> String { ... } }
Makes a mysql or sqlite con usable with dengine apis
Required Methods
fn execute<P>(&self, sql: &str, params: P) -> Desult<()> where
P: Clone,
Params: From<P>,
P: Clone,
Params: From<P>,
Executes a query with params
fn select<T: Queryable + Debug, P: Clone>(
&self,
sql: &str,
params: P,
calc_found_rows: bool
) -> Desult<SelectHolder<T>> where
Params: From<P>,
&self,
sql: &str,
params: P,
calc_found_rows: bool
) -> Desult<SelectHolder<T>> where
Params: From<P>,
Select sql query params- Individual value or Vec or Tuple calc_found_rows- If true count parameter in return structure is set to total number of calculated rows. Else return the number of rows returned
fn value<T, R>(&self, sql: &str, colum: &str, params: R) -> Desult<T> where
T: From<Dypes>,
R: Clone,
Params: From<R>,
T: From<Dypes>,
R: Clone,
Params: From<R>,
Returns scalar value colum: column name params: Params as in select
fn row<T, R>(&self, sql: &str, params: R) -> Desult<T> where
T: Queryable,
R: Clone,
Params: From<R>,
T: Queryable,
R: Clone,
Params: From<R>,
Return a single row params: Same as in select
fn insert_update<T: Insertable>(
&self,
table: &str,
fields: Vec<T>
) -> Desult<Affected>
&self,
table: &str,
fields: Vec<T>
) -> Desult<Affected>
Not tested
fn insert<T: Insertable>(&self, table: &str, fields: Vec<T>) -> Desult<Affected>
Insert a vector of structs into a table.
//Untested #[derive(Debug, Insertable)] struct User{ id: u64, name: String, } impl User{ pub fn new (id: u64, name: String) -> Self{ User{ id, name, } } } let mut data = Vec::new(); data.push(User::new(1, "name1")); data.push(User::new(2, "name2")); let affected = con.insert("user", data).unwrap();
fn update<T: Insertable>(
&self,
table: &str,
fields: Vec<T>,
where_fields: HashMap<&str, Dypes>
) -> Desult<Affected>
&self,
table: &str,
fields: Vec<T>,
where_fields: HashMap<&str, Dypes>
) -> Desult<Affected>
Update fields of a table where where_fields.key = where_fields.value
fn delete_ids<T>(
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>,
in_out: &str
) -> Desult<Affected> where
T: Clone,
Dypes: From<T>,
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>,
in_out: &str
) -> Desult<Affected> where
T: Clone,
Dypes: From<T>,
Delete rows
fn delete_wid<T>(
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>
) -> Desult<Affected> where
T: Clone,
Dypes: From<T>,
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>
) -> Desult<Affected> where
T: Clone,
Dypes: From<T>,
fn delete_nwid<T>(
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>
) -> Desult<Affected> where
T: Clone,
Dypes: From<T>,
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>
) -> Desult<Affected> where
T: Clone,
Dypes: From<T>,
fn concat_colums(colums: Vec<&str>) -> String
Provided Methods
fn array<T: Queryable + Debug, P: Clone>(
&self,
sql: &str,
params: P,
calc_found_rows: bool
) -> Desult<Vec<T>> where
Params: From<P>,
&self,
sql: &str,
params: P,
calc_found_rows: bool
) -> Desult<Vec<T>> where
Params: From<P>,
Return vector of rows instead of struct with meta data
fn gen_dupdate(colums: Vec<String>) -> String
Implementors
impl Connectionable for dengine::my_sql::Connection
impl Connectionable for dengine::sqlite::Connection