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 678B

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