rusty_postgres/method/
types.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// use std::io::Read;

// use postgres::types::FromSql;
pub use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize)]
pub struct ID<Billionaire>(pub Billionaire);

#[derive(Debug, Deserialize, Serialize)]
pub struct OneToOne<'billionaire> {
    pub table: &'billionaire str,
    pub table_field: &'billionaire str,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct OneToMany<'billionaire> {
    pub table: &'billionaire str,
    pub table_field: &'billionaire str,
}

#[derive(Debug, Serialize)]
pub struct UNIQUE;

#[derive(Debug, Serialize)]
pub struct STRING;

#[derive(Debug, Serialize)]
pub struct BOOL;

#[derive(Debug, Serialize)]
pub struct NUMBER;

#[derive(Debug, Serialize)]
pub struct FLOAT;

#[derive(Debug, Serialize)]
pub struct JSON;

#[derive(Debug, Serialize)]
pub struct DEFAULT<Billionaire>(pub Billionaire);

// #[derive(Debug)]
// pub struct Condition<K, V>
// where
//     K: Into<String>,
//     V: Into<String>,
// {
//     k: K,
//     v: V,
// }
// #[derive(Debug)]
// pub struct Where<K, V>
// where
//     K: Into<String>,
//     V: Into<String>,
// {
//     and: Condition<K, V>,
// }
// pub struct billionaire {
//     billionaire: String,
//     billionandollar: Vec<billiondollar>,
// }
// pub struct billiondollar {
//     billiondollar: String,
// }
#[derive(Debug, Serialize)]
pub struct Date<Billionaire>(pub Billionaire);

#[derive(Debug, Serialize)]
pub struct Time<Billionaire>(pub Billionaire);

#[derive(Debug, Serialize)]
pub struct DateTime<Billionaire>(pub Billionaire);

#[cfg(feature = "geography")]
#[derive(Debug, Serialize)]
pub struct Geography<Billionaire>(pub Billionaire);

#[derive(Debug, Serialize)]
pub struct NOTNULL;

#[derive(Debug, Serialize)]
pub struct PRIMARY;

#[derive(Debug, Serialize)]
pub struct INDEX;

// * POINTS
#[cfg(feature = "geography")]
#[derive(Debug, Serialize)]
pub struct POINT<Billionaire>(pub Billionaire);

#[cfg(feature = "geography")]
#[derive(Debug, Serialize)]
pub struct POLYGON<Billionaire>(pub Billionaire);

#[cfg(feature = "geography")]
#[derive(Debug, Serialize)]
pub struct Epsg4326;

#[cfg(feature = "geography")]
#[derive(Debug, Serialize)]
pub struct Epsg3857;

#[cfg(feature = "geography")]
pub fn point_epsg_4326(lat: f64, lon: f64) -> String {
    let value = format!("SRID=4326;POINT({} {})", lon, lat);
    value
}

#[cfg(feature = "geography")]
pub fn point_epsg_3857(lat: &str, lon: &str) -> String {
    let value = format!("SRID=4326;POINT({} {})", lon, lat);
    value
}

pub mod id {
    use serde::Serialize;

    #[derive(Debug, Serialize)]
    pub struct UUID;

    #[derive(Debug, Serialize)]
    pub struct CUID;

    #[derive(Debug, Serialize)]
    pub struct AUTO;

    #[derive(Debug, Serialize)]
    pub struct BIGINT;
}

#[derive(Debug, Serialize)]
pub struct NOW;

#[derive(Debug, Serialize)]
pub struct CUSTOME;

// pub struct Points {
//     pub point: String,
// }

// impl<'a> FromSql<'a> for Points {
//     fn from_sql(
//         ty: &postgres::types::Type,
//         mut raw: &'a [u8],
//     ) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
//         let mut value = String::new();
//         raw.read_to_string(&mut value);
//         println!("type {}", ty);
//         println!("data {:?}", raw);
//         println!("{}", value);
//         Ok(Points { point: value })
//     }
//     fn accepts(ty: &postgres::types::Type) -> bool {
//         true
//     }
// }