rusty_postgres/method/
types.rs

1// use std::io::Read;
2
3// use postgres::types::FromSql;
4pub use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Serialize)]
7pub struct ID<Billionaire>(pub Billionaire);
8
9#[derive(Debug, Deserialize, Serialize)]
10pub struct OneToOne<'billionaire> {
11    pub table: &'billionaire str,
12    pub table_field: &'billionaire str,
13}
14
15#[derive(Debug, Deserialize, Serialize)]
16pub struct OneToMany<'billionaire> {
17    pub table: &'billionaire str,
18    pub table_field: &'billionaire str,
19}
20
21#[derive(Debug, Serialize)]
22pub struct UNIQUE;
23
24#[derive(Debug, Serialize)]
25pub struct STRING;
26
27#[derive(Debug, Serialize)]
28pub struct BOOL;
29
30#[derive(Debug, Serialize)]
31pub struct NUMBER;
32
33#[derive(Debug, Serialize)]
34pub struct FLOAT;
35
36#[derive(Debug, Serialize)]
37pub struct JSON;
38
39#[derive(Debug, Serialize)]
40pub struct DEFAULT<Billionaire>(pub Billionaire);
41
42// #[derive(Debug)]
43// pub struct Condition<K, V>
44// where
45//     K: Into<String>,
46//     V: Into<String>,
47// {
48//     k: K,
49//     v: V,
50// }
51// #[derive(Debug)]
52// pub struct Where<K, V>
53// where
54//     K: Into<String>,
55//     V: Into<String>,
56// {
57//     and: Condition<K, V>,
58// }
59// pub struct billionaire {
60//     billionaire: String,
61//     billionandollar: Vec<billiondollar>,
62// }
63// pub struct billiondollar {
64//     billiondollar: String,
65// }
66#[derive(Debug, Serialize)]
67pub struct Date<Billionaire>(pub Billionaire);
68
69#[derive(Debug, Serialize)]
70pub struct Time<Billionaire>(pub Billionaire);
71
72#[derive(Debug, Serialize)]
73pub struct DateTime<Billionaire>(pub Billionaire);
74
75#[cfg(feature = "geography")]
76#[derive(Debug, Serialize)]
77pub struct Geography<Billionaire>(pub Billionaire);
78
79#[derive(Debug, Serialize)]
80pub struct NOTNULL;
81
82#[derive(Debug, Serialize)]
83pub struct PRIMARY;
84
85#[derive(Debug, Serialize)]
86pub struct INDEX;
87
88// * POINTS
89#[cfg(feature = "geography")]
90#[derive(Debug, Serialize)]
91pub struct POINT<Billionaire>(pub Billionaire);
92
93#[cfg(feature = "geography")]
94#[derive(Debug, Serialize)]
95pub struct POLYGON<Billionaire>(pub Billionaire);
96
97#[cfg(feature = "geography")]
98#[derive(Debug, Serialize)]
99pub struct Epsg4326;
100
101#[cfg(feature = "geography")]
102#[derive(Debug, Serialize)]
103pub struct Epsg3857;
104
105#[cfg(feature = "geography")]
106pub fn point_epsg_4326(lat: f64, lon: f64) -> String {
107    let value = format!("SRID=4326;POINT({} {})", lon, lat);
108    value
109}
110
111#[cfg(feature = "geography")]
112pub fn point_epsg_3857(lat: &str, lon: &str) -> String {
113    let value = format!("SRID=4326;POINT({} {})", lon, lat);
114    value
115}
116
117pub mod id {
118    use serde::Serialize;
119
120    #[derive(Debug, Serialize)]
121    pub struct UUID;
122
123    #[derive(Debug, Serialize)]
124    pub struct CUID;
125
126    #[derive(Debug, Serialize)]
127    pub struct AUTO;
128
129    #[derive(Debug, Serialize)]
130    pub struct BIGINT;
131}
132
133#[derive(Debug, Serialize)]
134pub struct NOW;
135
136#[derive(Debug, Serialize)]
137pub struct CUSTOME;
138
139// pub struct Points {
140//     pub point: String,
141// }
142
143// impl<'a> FromSql<'a> for Points {
144//     fn from_sql(
145//         ty: &postgres::types::Type,
146//         mut raw: &'a [u8],
147//     ) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
148//         let mut value = String::new();
149//         raw.read_to_string(&mut value);
150//         println!("type {}", ty);
151//         println!("data {:?}", raw);
152//         println!("{}", value);
153//         Ok(Points { point: value })
154//     }
155//     fn accepts(ty: &postgres::types::Type) -> bool {
156//         true
157//     }
158// }