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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
macro_rules! not_none {
    ($bytes:expr) => {
        match $bytes {
            Some(bytes) => bytes,
            None => return Err(Box::new(UnexpectedNullError {
                msg: "Unexpected null for non-null column".to_string(),
            })),
        }
    }
}

macro_rules! expression_impls {
    ($($Source:ident -> $Target:ty),+,) => {
        $(
            impl<'a> AsExpression<types::$Source> for $Target {
                type Expression = Bound<types::$Source, Self>;

                fn as_expression(self) -> Self::Expression {
                    Bound::new(self)
                }
            }

            impl<'a: 'expr, 'expr> AsExpression<types::$Source> for &'expr $Target {
                type Expression = Bound<types::$Source, Self>;

                fn as_expression(self) -> Self::Expression {
                    Bound::new(self)
                }
            }

            impl<'a> AsExpression<types::Nullable<types::$Source>> for $Target {
                type Expression = Bound<types::Nullable<types::$Source>, Self>;

                fn as_expression(self) -> Self::Expression {
                    Bound::new(self)
                }
            }

            impl<'a: 'expr, 'expr> AsExpression<types::Nullable<types::$Source>> for &'a $Target {
                type Expression = Bound<types::Nullable<types::$Source>, Self>;

                fn as_expression(self) -> Self::Expression {
                    Bound::new(self)
                }
            }

            impl<'a> ToSql<types::Nullable<types::$Source>> for $Target {
                fn to_sql<W: Write>(&self, out: &mut W) -> Result<IsNull, Box<Error>> {
                    <Self as ToSql<types::$Source>>::to_sql(self, out)
                }
            }
        )+
    }
}

macro_rules! queriable_impls {
    ($($Source:ident -> $Target:ty),+,) => {$(
        impl Queriable<types::$Source> for $Target {
            type Row = Self;

            fn build(row: Self::Row) -> Self {
                row
            }
        }
    )+}
}

macro_rules! primitive_impls {
    ($($Source:ident -> ($Target:ty, $oid:expr, $array_oid:expr)),+,) => {
        $(
            impl NativeSqlType for types::$Source {
                fn oid(&self) -> u32 {
                    $oid
                }

                fn array_oid(&self) -> u32 {
                    $array_oid
                }

                fn new() -> Self {
                    types::$Source
                }
            }
        )+
        queriable_impls!($($Source -> $Target),+,);
        expression_impls!($($Source -> $Target),+,);
    }
}

mod array;
pub mod date_and_time;
pub mod floats;
mod integers;
mod option;
mod primitives;
mod tuples;