1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::ops::Deref;
use std::rc::Rc;

pub mod model;
pub mod postgresql;
pub mod sqlite;

#[derive(Debug)]
pub struct Book<DB>
where
    DB: sqlx::database::Database,
{
    pool: Rc<sqlx::Pool<DB>>,
}

#[derive(Debug)]
pub struct Item<T, DB>
where
    DB: sqlx::database::Database,
{
    content: T,
    pool: Rc<sqlx::Pool<DB>>,
}

impl<T, DB> Item<T, DB>
where
    DB: sqlx::database::Database,
{
    fn new(content: T, pool: Rc<sqlx::Pool<DB>>) -> Self {
        Self {
            content,
            pool: Rc::clone(&pool),
        }
    }
}

impl<T, DB> Deref for Item<T, DB>
where
    DB: sqlx::database::Database,
{
    type Target = T;

    fn deref(&self) -> &T {
        &self.content
    }
}