tank_core/expression/
expression.rs1use crate::{
2 OpPrecedence, Value,
3 writer::{Context, SqlWriter},
4};
5use std::fmt::Debug;
6
7pub trait Expression: OpPrecedence + Send + Sync + Debug {
8 fn write_query(&self, writer: &dyn SqlWriter, context: &mut Context, buff: &mut String);
9 fn is_ordered(&self) -> bool {
10 false
11 }
12}
13
14impl<T: Expression> Expression for &T {
15 fn write_query(&self, writer: &dyn SqlWriter, context: &mut Context, buff: &mut String) {
16 (*self).write_query(writer, context, buff);
17 }
18 fn is_ordered(&self) -> bool {
19 (*self).is_ordered()
20 }
21}
22
23impl Expression for &dyn Expression {
24 fn write_query(&self, writer: &dyn SqlWriter, context: &mut Context, buff: &mut String) {
25 (*self).write_query(writer, context, buff);
26 }
27 fn is_ordered(&self) -> bool {
28 (*self).is_ordered()
29 }
30}
31
32impl Expression for () {
33 fn write_query(&self, _writer: &dyn SqlWriter, _context: &mut Context, _buff: &mut String) {}
34}
35
36impl Expression for bool {
37 fn write_query(&self, writer: &dyn SqlWriter, context: &mut Context, buff: &mut String) {
38 writer.write_value_bool(context, buff, *self);
39 }
40}
41
42impl<'a, T: Expression> From<&'a T> for &'a dyn Expression {
43 fn from(value: &'a T) -> Self {
44 value as &'a dyn Expression
45 }
46}
47
48impl Expression for Value {
49 fn write_query(&self, writer: &dyn SqlWriter, context: &mut Context, buff: &mut String) {
50 writer.write_value(context, buff, self);
51 }
52}