cratestack_sql/values/
into_sql.rs1use cratestack_core::Value;
2
3use super::sql_value::SqlValue;
4
5pub trait IntoSqlValue {
6 fn into_sql_value(self) -> SqlValue;
7}
8
9impl IntoSqlValue for bool {
10 fn into_sql_value(self) -> SqlValue {
11 SqlValue::Bool(self)
12 }
13}
14
15impl IntoSqlValue for i64 {
16 fn into_sql_value(self) -> SqlValue {
17 SqlValue::Int(self)
18 }
19}
20
21impl IntoSqlValue for f64 {
22 fn into_sql_value(self) -> SqlValue {
23 SqlValue::Float(self)
24 }
25}
26
27impl IntoSqlValue for String {
28 fn into_sql_value(self) -> SqlValue {
29 SqlValue::String(self)
30 }
31}
32
33impl IntoSqlValue for &str {
34 fn into_sql_value(self) -> SqlValue {
35 SqlValue::String(self.to_owned())
36 }
37}
38
39impl IntoSqlValue for uuid::Uuid {
40 fn into_sql_value(self) -> SqlValue {
41 SqlValue::Uuid(self)
42 }
43}
44
45impl IntoSqlValue for chrono::DateTime<chrono::Utc> {
46 fn into_sql_value(self) -> SqlValue {
47 SqlValue::DateTime(self)
48 }
49}
50
51impl IntoSqlValue for Value {
52 fn into_sql_value(self) -> SqlValue {
53 SqlValue::Json(self)
54 }
55}
56
57#[cfg(feature = "decimal-rust-decimal")]
65impl IntoSqlValue for rust_decimal::Decimal {
66 fn into_sql_value(self) -> SqlValue {
67 SqlValue::Decimal(Box::new(self))
68 }
69}
70
71#[cfg(feature = "decimal-bigdecimal")]
72impl IntoSqlValue for bigdecimal::BigDecimal {
73 fn into_sql_value(self) -> SqlValue {
74 SqlValue::Decimal(Box::new(self))
75 }
76}
77
78impl IntoSqlValue for Vec<f32> {
79 fn into_sql_value(self) -> SqlValue {
80 SqlValue::Vector(self)
81 }
82}