tank_core/expression/
operand.rs1use crate::{
2 Expression, OpPrecedence, Value,
3 writer::{Context, SqlWriter},
4};
5
6#[derive(Debug)]
7pub enum Operand<'a> {
8 LitBool(bool),
9 LitFloat(f64),
10 LitIdent(&'a str),
11 LitField(&'a [&'a str]),
12 LitInt(i128),
13 LitStr(&'a str),
14 LitArray(&'a [Operand<'a>]),
15 Null,
16 Type(Value),
17 Variable(Value),
18 Call(&'static str, &'a [&'a dyn Expression]),
19 Asterisk,
20 QuestionMark,
21}
22
23impl OpPrecedence for Operand<'_> {
24 fn precedence(&self, _writer: &dyn SqlWriter) -> i32 {
25 1_000_000
26 }
27}
28
29impl Expression for Operand<'_> {
30 fn write_query(&self, writer: &dyn SqlWriter, context: &mut Context, buff: &mut String) {
31 writer.write_expression_operand(context, buff, self)
32 }
33}
34
35impl PartialEq for Operand<'_> {
36 fn eq(&self, other: &Self) -> bool {
37 match (self, other) {
38 (Self::LitBool(l), Self::LitBool(r)) => l == r,
39 (Self::LitFloat(l), Self::LitFloat(r)) => l == r,
40 (Self::LitIdent(l), Self::LitIdent(r)) => l == r,
41 (Self::LitInt(l), Self::LitInt(r)) => l == r,
42 (Self::LitStr(l), Self::LitStr(r)) => l == r,
43 (Self::LitArray(l), Self::LitArray(r)) => l == r,
44 (Self::Type(l), Self::Type(r)) => l.same_type(r),
45 _ => false,
46 }
47 }
48}