use crate::{db::query::builder::aggregate::AggregateExpr, value::Value};
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) struct FieldId(String);
impl FieldId {
#[must_use]
pub(crate) fn new(field: impl Into<String>) -> Self {
Self(field.into())
}
#[must_use]
pub(crate) const fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl From<&str> for FieldId {
fn from(value: &str) -> Self {
Self::new(value)
}
}
impl From<String> for FieldId {
fn from(value: String) -> Self {
Self::new(value)
}
}
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) struct Alias(String);
impl Alias {
#[must_use]
pub(crate) fn new(name: impl Into<String>) -> Self {
Self(name.into())
}
#[must_use]
pub(crate) const fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl From<&str> for Alias {
fn from(value: &str) -> Self {
Self::new(value)
}
}
impl From<String> for Alias {
fn from(value: String) -> Self {
Self::new(value)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum UnaryOp {
Neg,
Not,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum BinaryOp {
Add,
Sub,
Mul,
Div,
And,
Or,
Eq,
Ne,
Lt,
Lte,
Gt,
Gte,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) enum Expr {
Field(FieldId),
Literal(Value),
Unary {
op: UnaryOp,
expr: Box<Self>,
},
Binary {
op: BinaryOp,
left: Box<Self>,
right: Box<Self>,
},
Aggregate(AggregateExpr),
Alias {
expr: Box<Self>,
name: Alias,
},
}