lsor_core/
var.rs

1use chrono::{DateTime, Utc};
2use uuid::Uuid;
3
4use crate::driver::PushPrql;
5
6pub fn zero() -> Literal {
7    Literal::I32(0)
8}
9
10pub fn one() -> Literal {
11    Literal::I32(1)
12}
13
14pub fn lit(x: impl Into<Literal>) -> Literal {
15    x.into()
16}
17
18#[derive(Clone, Debug, Eq, PartialEq)]
19pub enum Var {
20    Bool(bool),
21    I32(i32),
22    I64(i64),
23    String(String),
24    Uuid(Uuid),
25    DateTime(DateTime<Utc>),
26}
27
28impl PushPrql for Var {
29    fn push_to_driver(&self, driver: &mut crate::driver::Driver) {
30        match self {
31            Self::Bool(x) => driver.push_bind(x),
32            Self::I32(x) => driver.push_bind(x),
33            Self::I64(x) => driver.push_bind(x),
34            Self::String(x) => driver.push_bind(x),
35            Self::Uuid(x) => driver.push_bind(x),
36            Self::DateTime(x) => driver.push_bind(x),
37        };
38    }
39}
40
41#[derive(Clone, Debug, Eq, PartialEq)]
42pub enum Literal {
43    Bool(bool),
44    I32(i32),
45    I64(i64),
46    String(String),
47    Uuid(Uuid),
48}
49
50impl From<bool> for Literal {
51    fn from(x: bool) -> Self {
52        Self::Bool(x)
53    }
54}
55
56impl From<i32> for Literal {
57    fn from(x: i32) -> Self {
58        Self::I32(x)
59    }
60}
61
62impl From<i64> for Literal {
63    fn from(x: i64) -> Self {
64        Self::I64(x)
65    }
66}
67
68impl From<String> for Literal {
69    fn from(x: String) -> Self {
70        Self::String(x)
71    }
72}
73
74impl From<Uuid> for Literal {
75    fn from(x: Uuid) -> Self {
76        Self::Uuid(x)
77    }
78}
79
80impl PushPrql for Literal {
81    fn push_to_driver(&self, driver: &mut crate::driver::Driver) {
82        match self {
83            Self::Bool(x) => driver.push(x),
84            Self::I32(x) => driver.push(x),
85            Self::I64(x) => driver.push(x),
86            Self::String(x) => driver.push(x),
87            Self::Uuid(x) => driver.push(x),
88        };
89    }
90}