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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
pub mod ops;
mod ord;
#[macro_use]
#[doc(hidden)]
pub mod impls;
mod fold;
#[doc(hidden)]
pub mod structs {
pub mod data_types {
#[cfg(feature = "postgres")]
pub use pg::data_types::*;
}
}
pub use self::ord::SqlOrd;
pub use self::fold::Foldable;
use backend::{Backend, TypeMetadata};
use row::Row;
use std::error::Error;
use std::io::Write;
#[derive(Clone, Copy, Default)] pub struct Bool;
#[derive(Clone, Copy, Default)] pub struct SmallInt;
#[doc(hidden)] pub type Int2 = SmallInt;
#[derive(Clone, Copy, Default)] pub struct Integer;
#[doc(hidden)] pub type Int4 = Integer;
#[derive(Clone, Copy, Default)] pub struct BigInt;
#[doc(hidden)] pub type Int8 = BigInt;
#[derive(Clone, Copy, Default)] pub struct Float;
#[doc(hidden)] pub type Float4 = Float;
#[derive(Clone, Copy, Default)] pub struct Double;
#[doc(hidden)] pub type Float8 = Double;
#[derive(Clone, Copy, Default)] pub struct Numeric;
#[derive(Clone, Copy, Default)] pub struct VarChar;
#[doc(hidden)] pub type Varchar = VarChar;
#[derive(Clone, Copy, Default)] pub struct Text;
#[derive(Clone, Copy, Default)] pub struct Binary;
#[derive(Clone, Copy, Default)] pub struct Date;
#[derive(Clone, Copy, Default)] pub struct Interval;
#[derive(Clone, Copy, Default)] pub struct Time;
#[derive(Clone, Copy, Default)] pub struct Timestamp;
#[derive(Clone, Copy, Default)] pub struct Nullable<T: NotNull>(T);
#[cfg(feature = "postgres")]
#[doc(inline)]
pub use pg::types::sql_types::*;
pub trait HasSqlType<ST>: TypeMetadata {
fn metadata() -> Self::TypeMetadata;
}
pub trait NotNull {
}
pub trait IntoNullable {
type Nullable;
}
impl<T: NotNull> IntoNullable for T {
type Nullable = Nullable<T>;
}
impl<T: NotNull> IntoNullable for Nullable<T> {
type Nullable = Nullable<T>;
}
pub trait FromSql<A, DB: Backend + HasSqlType<A>>: Sized {
fn from_sql(bytes: Option<&DB::RawValue>) -> Result<Self, Box<Error+Send+Sync>>;
}
pub trait FromSqlRow<A, DB: Backend + HasSqlType<A>>: Sized {
fn build_from_row<T: Row<DB>>(row: &mut T) -> Result<Self, Box<Error+Send+Sync>>;
}
#[cfg(feature = "unstable")]
include!("specialization_impls.rs");
#[derive(Debug, PartialEq, Eq)]
pub enum IsNull {
Yes,
No,
}
pub trait ToSql<A, DB: Backend + HasSqlType<A>> {
fn to_sql<W: Write>(&self, out: &mut W) -> Result<IsNull, Box<Error+Send+Sync>>;
}
impl<'a, A, T, DB> ToSql<A, DB> for &'a T where
DB: Backend + HasSqlType<A>,
T: ToSql<A, DB>,
{
fn to_sql<W: Write>(&self, out: &mut W) -> Result<IsNull, Box<Error+Send+Sync>> {
(*self).to_sql(out)
}
}