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    BigInt(i64),
8    Float(f64),
9    Str(String),
10    Bytes(Vec<u8>),
11    Date(String),
12    DateTime(String),
13    Time(String),
14    Decimal(String),
15    Uuid(String),
16    Json(String),
17    Jsonb(String),
18    IpNetwork(String),
19    Array(Vec<Value>),
20    Vector(Vec<f32>),
21    TimeDelta {
22        years: i32,
23        months: i32,
24        days: i64,
25        seconds: i64,
26        microseconds: i64,
27    },
28}
29
30impl From<i64> for Value {
31    fn from(v: i64) -> Self {
32        Value::Int(v)
33    }
34}
35
36impl From<i32> for Value {
37    fn from(v: i32) -> Self {
38        Value::Int(v as i64)
39    }
40}
41
42impl From<f64> for Value {
43    fn from(v: f64) -> Self {
44        Value::Float(v)
45    }
46}
47
48impl From<bool> for Value {
49    fn from(v: bool) -> Self {
50        Value::Bool(v)
51    }
52}
53
54impl From<String> for Value {
55    fn from(v: String) -> Self {
56        Value::Str(v)
57    }
58}
59
60impl From<&str> for Value {
61    fn from(v: &str) -> Self {
62        Value::Str(v.to_string())
63    }
64}
65
66impl From<Vec<u8>> for Value {
67    fn from(v: Vec<u8>) -> Self {
68        Value::Bytes(v)
69    }
70}