pub trait Connectionable {
Show 13 methods
// Required methods
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;
// 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> { ... }
fn gen_dupdate(colums: Vec<String>) -> String { ... }
}
Expand description
Makes a mysql or sqlite con usable with dengine apis
Required Methods§
Sourcefn select<T: Queryable + Debug, P: Clone>(
&self,
sql: &str,
params: P,
calc_found_rows: bool,
) -> Desult<SelectHolder<T>>
fn select<T: Queryable + Debug, P: Clone>( &self, sql: &str, params: P, calc_found_rows: bool, ) -> Desult<SelectHolder<T>>
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
Sourcefn value<T, R>(&self, sql: &str, colum: &str, params: R) -> Desult<T>
fn value<T, R>(&self, sql: &str, colum: &str, params: R) -> Desult<T>
Returns scalar value colum: column name params: Params as in select
Sourcefn row<T, R>(&self, sql: &str, params: R) -> Desult<T>
fn row<T, R>(&self, sql: &str, params: R) -> Desult<T>
Return a single row params: Same as in select
Sourcefn insert_update<T: Insertable>(
&self,
table: &str,
fields: Vec<T>,
) -> Desult<Affected>
fn insert_update<T: Insertable>( &self, table: &str, fields: Vec<T>, ) -> Desult<Affected>
Not tested
Sourcefn insert<T: Insertable>(&self, table: &str, fields: Vec<T>) -> Desult<Affected>
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();
Sourcefn update<T: Insertable>(
&self,
table: &str,
fields: Vec<T>,
where_fields: HashMap<&str, Dypes>,
) -> Desult<Affected>
fn update<T: Insertable>( &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
Sourcefn delete_ids<T>(
&self,
table: &str,
id_colum: &str,
id_values: Vec<T>,
in_out: &str,
) -> Desult<Affected>
fn delete_ids<T>( &self, table: &str, id_colum: &str, id_values: Vec<T>, in_out: &str, ) -> Desult<Affected>
Delete rows
fn delete_wid<T>( &self, table: &str, id_colum: &str, id_values: Vec<T>, ) -> Desult<Affected>
fn delete_nwid<T>( &self, table: &str, id_colum: &str, id_values: Vec<T>, ) -> Desult<Affected>
fn concat_colums(colums: Vec<&str>) -> String
Provided Methods§
Sourcefn array<T: Queryable + Debug, P: Clone>(
&self,
sql: &str,
params: P,
calc_found_rows: bool,
) -> Desult<Vec<T>>
fn array<T: Queryable + Debug, P: Clone>( &self, sql: &str, params: P, calc_found_rows: bool, ) -> Desult<Vec<T>>
Return vector of rows instead of struct with meta data
fn gen_dupdate(colums: Vec<String>) -> String
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.