Update macro to use #[index] attributes
- Also use proper types for index. - Update DB interface to be more flexible for index params Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::borrow::Borrow;
|
||||
|
||||
use crate::models::{Index, Model};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -22,9 +24,11 @@ where
|
||||
type Error: std::fmt::Debug;
|
||||
|
||||
/// Get all items where the given index field is equal to key.
|
||||
fn get<I>(&self, key: &I::Key) -> Result<Vec<V>, Error<Self::Error>>
|
||||
fn get<I, Q>(&self, key: &Q) -> Result<Vec<V>, Error<Self::Error>>
|
||||
where
|
||||
I: Index<Model = V>;
|
||||
I: Index<Model = V>,
|
||||
I::Key: Borrow<Q>,
|
||||
Q: ToString + ?Sized;
|
||||
|
||||
/// Get an object from its ID. This does not use an index lookup
|
||||
fn get_by_id(&self, id: u32) -> Result<Option<V>, Error<Self::Error>>;
|
||||
@@ -33,9 +37,11 @@ where
|
||||
fn set(&self, value: &V) -> Result<(), Error<Self::Error>>;
|
||||
|
||||
/// Delete all items from the db with a given index.
|
||||
fn delete<I>(&self, key: &I::Key) -> Result<(), Error<Self::Error>>
|
||||
fn delete<I, Q>(&self, key: &Q) -> Result<(), Error<Self::Error>>
|
||||
where
|
||||
I: Index<Model = V>;
|
||||
I: Index<Model = V>,
|
||||
I::Key: Borrow<Q>,
|
||||
Q: ToString + ?Sized;
|
||||
|
||||
/// Delete an object with a given ID
|
||||
fn delete_by_id(&self, id: u32) -> Result<(), Error<Self::Error>>;
|
||||
|
Reference in New Issue
Block a user