A tool to compile SQL to Elasticsearch queries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ast.rs 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #[derive(Debug, PartialEq)]
  2. pub struct Select {
  3. pub fields: Vec<Field>,
  4. pub source: KIdentifier,
  5. pub where_clause: Option<Where>,
  6. }
  7. #[derive(Debug, PartialEq)]
  8. pub enum Field {
  9. Named(String),
  10. Star,
  11. }
  12. #[derive(Debug, PartialEq)]
  13. pub struct Where {
  14. pub predicates: Vec<Equals>,
  15. }
  16. impl Where {
  17. pub fn new(predicates: Vec<Equals>) -> Self {
  18. Self { predicates }
  19. }
  20. }
  21. #[derive(Debug, PartialEq)]
  22. pub struct Equals {
  23. pub left: KIdentifier,
  24. pub right: KValue,
  25. }
  26. impl Equals {
  27. pub fn new(left: KIdentifier, right: KValue) -> Self {
  28. Self { left, right }
  29. }
  30. }
  31. #[derive(Debug, PartialEq)]
  32. pub enum KValue {
  33. Identifier(KIdentifier),
  34. Number(KNumber),
  35. String(KString),
  36. }
  37. #[derive(Debug, PartialEq)]
  38. pub struct KIdentifier {
  39. pub name: String,
  40. }
  41. #[derive(Debug, PartialEq)]
  42. pub struct KNumber {
  43. pub value: f64,
  44. }
  45. #[derive(Debug, PartialEq)]
  46. pub struct KString {
  47. pub value: String,
  48. }
  49. impl KIdentifier {
  50. pub fn new(name: &str) -> Self {
  51. Self {
  52. name: name.to_string(),
  53. }
  54. }
  55. }
  56. impl KNumber {
  57. pub fn new(value: f64) -> Self {
  58. Self { value }
  59. }
  60. }
  61. impl KString {
  62. pub fn new(value: &str) -> Self {
  63. Self {
  64. value: value.to_string(),
  65. }
  66. }
  67. }