pub trait Query {
type Model;
const TABLE_NAME: &'static str;
const PRIMARY_KEY: &'static str = "id";
// Required method
fn process_row(row: &Row<'_>) -> Self::Model;
// Provided methods
fn query(
conn: &Connection,
query: &str,
params: impl Params,
) -> Vec<Self::Model> { ... }
fn get(
conn: &Connection,
query: &str,
params: impl Params,
) -> Result<Self::Model> { ... }
fn get_by_id<'a, T>(conn: &Connection, id: &'a T) -> Option<Self::Model>
where T: Clone + 'a,
Value: From<T> { ... }
fn query_by_ids<'a, I: ?Sized, T>(
conn: &Connection,
ids: &'a I,
) -> Vec<Self::Model>
where &'a I: IntoIterator<Item = &'a T>,
T: Clone + 'a,
Value: From<T> { ... }
fn delete_by_ids<'a, I: ?Sized, T>(
conn: &Connection,
ids: &'a I,
) -> Vec<Self::Model>
where &'a I: IntoIterator<Item = &'a T>,
T: Clone + 'a,
Value: From<T> { ... }
fn table_name() -> &'static str { ... }
fn all(conn: &Connection) -> Vec<Self::Model> { ... }
fn all_with_limit(conn: &Connection, limit: usize) -> Vec<Self::Model> { ... }
}Required Associated Constants§
const TABLE_NAME: &'static str
Provided Associated Constants§
const PRIMARY_KEY: &'static str = "id"
Required Associated Types§
Required Methods§
fn process_row(row: &Row<'_>) -> Self::Model
Provided Methods§
fn query( conn: &Connection, query: &str, params: impl Params, ) -> Vec<Self::Model>
fn get( conn: &Connection, query: &str, params: impl Params, ) -> Result<Self::Model>
fn get_by_id<'a, T>(conn: &Connection, id: &'a T) -> Option<Self::Model>
fn query_by_ids<'a, I: ?Sized, T>( conn: &Connection, ids: &'a I, ) -> Vec<Self::Model>
fn delete_by_ids<'a, I: ?Sized, T>( conn: &Connection, ids: &'a I, ) -> Vec<Self::Model>
fn table_name() -> &'static str
fn all(conn: &Connection) -> Vec<Self::Model>
fn all_with_limit(conn: &Connection, limit: usize) -> Vec<Self::Model>
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.