Skip to main content

qcraft_core/ast/
value.rs

1/// A database value used in expressions, parameters, and defaults.
2#[derive(Debug, Clone, PartialEq)]
3pub enum Value {
4    Null,
5    Bool(bool),
6    Int(i64),
7    Float(f64),
8    Str(String),
9    Bytes(Vec<u8>),
10    Date(String),
11    DateTime(String),
12    Time(String),
13    Decimal(String),
14    Uuid(String),
15    Json(String),
16    Jsonb(String),
17    IpNetwork(String),
18    Array(Vec<Value>),
19    Vector(Vec<f32>),
20    TimeDelta {
21        years: i32,
22        months: i32,
23        days: i64,
24        seconds: i64,
25        microseconds: i64,
26    },
27}
28
29impl From<i64> for Value {
30    fn from(v: i64) -> Self {
31        Value::Int(v)
32    }
33}
34
35impl From<i32> for Value {
36    fn from(v: i32) -> Self {
37        Value::Int(v as i64)
38    }
39}
40
41impl From<f64> for Value {
42    fn from(v: f64) -> Self {
43        Value::Float(v)
44    }
45}
46
47impl From<bool> for Value {
48    fn from(v: bool) -> Self {
49        Value::Bool(v)
50    }
51}
52
53impl From<String> for Value {
54    fn from(v: String) -> Self {
55        Value::Str(v)
56    }
57}
58
59impl From<&str> for Value {
60    fn from(v: &str) -> Self {
61        Value::Str(v.to_string())
62    }
63}
64
65impl From<Vec<u8>> for Value {
66    fn from(v: Vec<u8>) -> Self {
67        Value::Bytes(v)
68    }
69}