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.

lib.rs 665B

1234567891011121314151617181920212223242526272829
  1. pub mod compiler;
  2. pub mod error;
  3. pub mod lexer;
  4. pub mod parser;
  5. pub mod token;
  6. use wasm_bindgen::prelude::*;
  7. #[wasm_bindgen]
  8. pub fn compile(input: &str) -> String {
  9. let tokens = match lexer::scan(&input) {
  10. Ok(tokens) => tokens,
  11. Err(e) => return e.message,
  12. };
  13. let select = match parser::parse(tokens) {
  14. Ok(select) => select,
  15. Err(e) => return e.message,
  16. };
  17. let query = match compiler::compile(select) {
  18. Ok(query) => query,
  19. Err(e) => return e.message,
  20. };
  21. format!(
  22. "GET /{}/_search\n{}",
  23. query.source.name,
  24. serde_json::to_string_pretty(&query.body).unwrap()
  25. )
  26. }