|
@@ -1,5 +1,7 @@
|
1
|
1
|
use serde_json::{json, Value};
|
2
|
2
|
|
|
3
|
+use std::fmt::{Display, Formatter};
|
|
4
|
+
|
3
|
5
|
use crate::error::CompilerError;
|
4
|
6
|
use crate::parser::{Field, Identifier, Select};
|
5
|
7
|
|
|
@@ -15,6 +17,17 @@ impl Query {
|
15
|
17
|
}
|
16
|
18
|
}
|
17
|
19
|
|
|
20
|
+impl Display for Query {
|
|
21
|
+ fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
|
22
|
+ let header = format!("GET /{}/_search", self.source.name);
|
|
23
|
+ let body = match serde_json::to_string_pretty(&self.body) {
|
|
24
|
+ Ok(body) => body,
|
|
25
|
+ Err(_) => return Err(std::fmt::Error {}),
|
|
26
|
+ };
|
|
27
|
+ write!(f, "{}\n{}", header, body)
|
|
28
|
+ }
|
|
29
|
+}
|
|
30
|
+
|
18
|
31
|
pub fn compile(expr: Select) -> Result<Query, CompilerError> {
|
19
|
32
|
let mut source = false;
|
20
|
33
|
let field_names: Vec<Value> = expr
|