Skip to main content

surrealdb_sql/
constant.rs

1use surrealdb_types::{SqlFormat, ToSql};
2
3#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
4#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
5pub enum Constant {
6	MathE,
7	MathFrac1Pi,
8	MathFrac1Sqrt2,
9	MathFrac2Pi,
10	MathFrac2SqrtPi,
11	MathFracPi2,
12	MathFracPi3,
13	MathFracPi4,
14	MathFracPi6,
15	MathFracPi8,
16	MathInfinity,
17	MathLn10,
18	MathLn2,
19	MathLog102,
20	MathLog10E,
21	MathLog210,
22	MathLog2E,
23	MathNegInfinity,
24	MathPi,
25	MathSqrt2,
26	MathTau,
27	TimeEpoch,
28	TimeMin,
29	TimeMax,
30	DurationMax,
31	// Add new variants here
32}
33
34impl ToSql for Constant {
35	fn fmt_sql(&self, f: &mut String, _fmt: SqlFormat) {
36		f.push_str(match self {
37			Self::MathE => "math::E",
38			Self::MathFrac1Pi => "math::FRAC_1_PI",
39			Self::MathFrac1Sqrt2 => "math::FRAC_1_SQRT_2",
40			Self::MathFrac2Pi => "math::FRAC_2_PI",
41			Self::MathFrac2SqrtPi => "math::FRAC_2_SQRT_PI",
42			Self::MathFracPi2 => "math::FRAC_PI_2",
43			Self::MathFracPi3 => "math::FRAC_PI_3",
44			Self::MathFracPi4 => "math::FRAC_PI_4",
45			Self::MathFracPi6 => "math::FRAC_PI_6",
46			Self::MathFracPi8 => "math::FRAC_PI_8",
47			Self::MathInfinity => "math::INFINITY",
48			Self::MathLn10 => "math::LN_10",
49			Self::MathLn2 => "math::LN_2",
50			Self::MathLog102 => "math::LOG10_2",
51			Self::MathLog10E => "math::LOG10_E",
52			Self::MathLog210 => "math::LOG2_10",
53			Self::MathLog2E => "math::LOG2_E",
54			Self::MathNegInfinity => "math::NEG_INFINITY",
55			Self::MathPi => "math::PI",
56			Self::MathSqrt2 => "math::SQRT_2",
57			Self::MathTau => "math::TAU",
58			Self::TimeEpoch => "time::EPOCH",
59			Self::TimeMin => "time::MINIMUM",
60			Self::TimeMax => "time::MAXIMUM",
61			Self::DurationMax => "duration::MAX",
62		})
63	}
64}