taitan_orm_trait/
selected.rs

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::selection::Selection;
use crate::NotImplementError;
use sqlx::types::Uuid;
use sqlx::{ColumnIndex, Database, Decode, Type};
use std::fmt::Debug;
use time::PrimitiveDateTime;

pub trait SelectedEntity<DB: Database>: Debug + Default {
    type Selection: Selection;
    fn from_row(selection: &Self::Selection, row: DB::Row) -> Result<Self, sqlx::Error>
    where
        Self: Sized;

    // fn from_row_bits(bits: &bit_vec::BitVec, row: DB::Row) -> Result<Self, sqlx::Error>
    // where
    //     Self: Sized,
    // {
    //     todo!()
    // }

    fn select_from_row(selection: &Self, row: DB::Row) -> Result<Self, sqlx::Error>
    where
        Self: Sized,
    {
        todo!()
    }

    fn from_row_full(row: DB::Row) -> Result<Self, sqlx::Error>
    where
        Self: Sized,
    {
        Err(sqlx::Error::Decode(
            NotImplementError("".to_string()).into(),
        ))
    }
}

pub trait SelectedEntityNew: Debug + Default {
    type Selection: Selection;
    fn from_row<DB: Database>(
        selection: &Self::Selection,
        row: DB::Row,
    ) -> Result<Self, sqlx::Error>
    where
        Self: Sized,
        for<'a> PrimitiveDateTime: Type<DB> + Decode<'a, DB>,
        for<'a> i32: Type<DB> + Decode<'a, DB>,
        for<'a> String: Type<DB> + Decode<'a, DB>,
        for<'a> Uuid: Type<DB> + Decode<'a, DB>,
        for<'a> u64: Type<DB> + Decode<'a, DB>,
        for<'a> &'a str: ColumnIndex<DB::Row>,
        usize: ColumnIndex<DB::Row>;

    fn from_row_full<DB: Database>(row: DB::Row) -> Result<Self, sqlx::Error>
    where
        Self: Sized,
    {
        Err(sqlx::Error::Decode(
            NotImplementError("".to_string()).into(),
        ))
    }
}