Skip to main content

sea_query_sqlx/
sqlx_any.rs

1use crate::SqlxValues;
2use sea_query::{OptionEnum, Value};
3
4impl<'q> sqlx::IntoArguments<'q, sqlx::any::Any> for SqlxValues {
5    fn into_arguments(self) -> sqlx::any::AnyArguments<'q> {
6        let mut args = sqlx::any::AnyArguments::default();
7        for arg in self.0.into_iter() {
8            use sqlx::Arguments;
9            match arg {
10                Value::Bool(b) => {
11                    let _ = args.add(b);
12                }
13                Value::TinyInt(i) => {
14                    let _ = args.add(i.map(Into::<i32>::into));
15                }
16                Value::SmallInt(i) => {
17                    let _ = args.add(i.map(Into::<i32>::into));
18                }
19                Value::Int(i) => {
20                    let _ = args.add(i);
21                }
22                Value::BigInt(i) => {
23                    let _ = args.add(i);
24                }
25                Value::TinyUnsigned(i) => {
26                    let _ = args.add(i.map(Into::<i32>::into));
27                }
28                Value::SmallUnsigned(i) => {
29                    let _ = args.add(i.map(Into::<i32>::into));
30                }
31                Value::Unsigned(i) => {
32                    let _ = args.add(i.map(Into::<i64>::into));
33                }
34                Value::BigUnsigned(i) => {
35                    let _ = args
36                        .add(i.map(|i| <i64 as std::convert::TryFrom<u64>>::try_from(i).unwrap()));
37                }
38                Value::Float(f) => {
39                    let _ = args.add(f);
40                }
41                Value::Double(d) => {
42                    let _ = args.add(d);
43                }
44                Value::String(s) => {
45                    let _ = args.add(s);
46                }
47                Value::Enum(e) => {
48                    let value = match e {
49                        OptionEnum::Some(v) => Some(v.value.into_owned()),
50                        OptionEnum::None(_) => None,
51                    };
52                    let _ = args.add(value);
53                }
54                Value::Char(c) => {
55                    let _ = args.add(c.map(|c| c.to_string()));
56                }
57                Value::Bytes(b) => {
58                    let _ = args.add(b);
59                }
60                #[cfg(feature = "with-chrono")]
61                Value::ChronoDate(t) => {
62                    let _ = args.add(Value::ChronoDate(t).chrono_as_naive_utc_in_string());
63                }
64                #[cfg(feature = "with-chrono")]
65                Value::ChronoTime(t) => {
66                    let _ = args.add(Value::ChronoTime(t).chrono_as_naive_utc_in_string());
67                }
68                #[cfg(feature = "with-chrono")]
69                Value::ChronoDateTime(t) => {
70                    let _ = args.add(Value::ChronoDateTime(t).chrono_as_naive_utc_in_string());
71                }
72                #[cfg(feature = "with-chrono")]
73                Value::ChronoDateTimeUtc(t) => {
74                    let _ = args.add(Value::ChronoDateTimeUtc(t).chrono_as_naive_utc_in_string());
75                }
76                #[cfg(feature = "with-chrono")]
77                Value::ChronoDateTimeLocal(t) => {
78                    let _ = args.add(Value::ChronoDateTimeLocal(t).chrono_as_naive_utc_in_string());
79                }
80                #[cfg(feature = "with-chrono")]
81                Value::ChronoDateTimeWithTimeZone(t) => {
82                    let _ = args
83                        .add(Value::ChronoDateTimeWithTimeZone(t).chrono_as_naive_utc_in_string());
84                }
85                #[cfg(feature = "with-time")]
86                Value::TimeDate(t) => {
87                    let _ = args.add(Value::TimeDate(t).time_as_naive_utc_in_string());
88                }
89                #[cfg(feature = "with-time")]
90                Value::TimeTime(t) => {
91                    let _ = args.add(Value::TimeTime(t).time_as_naive_utc_in_string());
92                }
93                #[cfg(feature = "with-time")]
94                Value::TimeDateTime(t) => {
95                    let _ = args.add(Value::TimeDateTime(t).time_as_naive_utc_in_string());
96                }
97                #[cfg(feature = "with-time")]
98                Value::TimeDateTimeWithTimeZone(t) => {
99                    let _ =
100                        args.add(Value::TimeDateTimeWithTimeZone(t).time_as_naive_utc_in_string());
101                }
102                #[cfg(feature = "with-uuid")]
103                Value::Uuid(_) => {
104                    panic!("UUID support not implemented for Any");
105                }
106                #[cfg(feature = "with-rust_decimal")]
107                Value::Decimal(_) => {
108                    panic!("Sqlite doesn't support decimal arguments");
109                }
110                #[cfg(feature = "with-bigdecimal")]
111                Value::BigDecimal(_) => {
112                    panic!("Sqlite doesn't support bigdecimal arguments");
113                }
114                #[cfg(feature = "with-json")]
115                Value::Json(_) => {
116                    panic!("Json support not implemented for Any");
117                }
118                #[cfg(feature = "with-ipnetwork")]
119                Value::IpNetwork(_) => {
120                    panic!("SQLx doesn't support IpNetwork arguments for Any");
121                }
122                #[cfg(feature = "with-mac_address")]
123                Value::MacAddress(_) => {
124                    panic!("SQLx doesn't support MacAddress arguments for Any");
125                }
126                #[cfg(feature = "postgres-array")]
127                Value::Array(_, _) => {
128                    panic!("SQLx doesn't support array arguments for Any");
129                }
130                #[cfg(feature = "postgres-vector")]
131                Value::Vector(_) => {
132                    panic!("SQLx doesn't support vector arguments for Any");
133                } /* #[cfg(feature = "postgres-range")]
134                  Value::Range(_) => {
135                      panic!("SQLx doesn't support PgRange arguments for Any");
136                  } */
137            }
138        }
139        args
140    }
141}