grafbase_sql_ast/ast/
ops.rs

1use crate::ast::Expression;
2use std::ops::{Add, Div, Mul, Rem, Sub};
3
4/// Calculation operations in SQL queries.
5#[derive(Debug, PartialEq, Clone)]
6pub enum SqlOp<'a> {
7    Add(Expression<'a>, Expression<'a>),
8    Sub(Expression<'a>, Expression<'a>),
9    Mul(Expression<'a>, Expression<'a>),
10    Div(Expression<'a>, Expression<'a>),
11    Rem(Expression<'a>, Expression<'a>),
12    Append(Expression<'a>, Expression<'a>),
13    JsonDeleteAtPath(Expression<'a>, Expression<'a>),
14}
15
16impl<'a> Add for Expression<'a> {
17    type Output = Expression<'a>;
18
19    fn add(self, other: Self) -> Self {
20        SqlOp::Add(self, other).into()
21    }
22}
23
24impl<'a> Sub for Expression<'a> {
25    type Output = Expression<'a>;
26
27    fn sub(self, other: Self) -> Self {
28        SqlOp::Sub(self, other).into()
29    }
30}
31
32impl<'a> Mul for Expression<'a> {
33    type Output = Expression<'a>;
34
35    fn mul(self, other: Self) -> Self {
36        SqlOp::Mul(self, other).into()
37    }
38}
39
40impl<'a> Div for Expression<'a> {
41    type Output = Expression<'a>;
42
43    fn div(self, other: Self) -> Self {
44        SqlOp::Div(self, other).into()
45    }
46}
47
48impl<'a> Rem for Expression<'a> {
49    type Output = Expression<'a>;
50
51    fn rem(self, other: Self) -> Self {
52        SqlOp::Rem(self, other).into()
53    }
54}