Skip to content

Instantly share code, notes, and snippets.

@dutchmartin
Last active October 25, 2019 13:09
Show Gist options
  • Save dutchmartin/574296f7d52501a6522027b2a34aef48 to your computer and use it in GitHub Desktop.
Save dutchmartin/574296f7d52501a6522027b2a34aef48 to your computer and use it in GitHub Desktop.
sprattus traits
pub trait FromSql {
fn from_row(row: &Row) -> Result<Self, Error>
where
Self: Sized;
}
pub trait ToSql {
type PK;
fn get_primary_key_value(&self) -> Self::PK
where
Self::PK: ToSqlItem + Sized + Sync;
fn get_table_name() -> &'static str;
fn get_primary_key() -> &'static str;
fn get_fields() -> &'static str;
fn get_all_fields() -> &'static str;
fn get_values_of_all_fields(&self) -> Vec<&(dyn ToSqlItem + Sync)>;
fn get_query_params(&self) -> Vec<&(dyn ToSqlItem + Sync)>;
fn get_prepared_arguments_list() -> &'static str;
fn get_prepared_arguments_list_with_types() -> &'static str;
fn get_argument_count() -> usize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment