Added trait to interact with database
something which any database related type should implement soon
This commit is contained in:
parent
31e011ac49
commit
d91666658b
25
server-api/db/src/common.rs
Normal file
25
server-api/db/src/common.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
use mysql_async::Pool;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
use crate::Response;
|
||||||
|
use crate::UBigInt;
|
||||||
|
|
||||||
|
pub const NO_CONN_MSG: &'static str = "No connection could be established";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: pay attention to work on async in traits for rust
|
||||||
|
* Each of one these funcs will implicitly do a single heap allocation which
|
||||||
|
* for our case is fine though ideally we don't
|
||||||
|
*
|
||||||
|
* As soon as we finda way around that we should depecrate `#[async_trait`
|
||||||
|
* for the performance
|
||||||
|
* */
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait FromDB<T> {
|
||||||
|
type Row;
|
||||||
|
|
||||||
|
async fn get(p: &Pool, id: UBigInt) -> Response<T>;
|
||||||
|
|
||||||
|
async fn update(p: &Pool, row: T) -> Response<T>;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user