From cced802c87fe099905cfbd15a32a399698f9f8b7 Mon Sep 17 00:00:00 2001 From: alemidev Date: Thu, 9 Jun 2022 01:38:52 +0200 Subject: [PATCH] build: dropped jq_rs in favor of jql --- Cargo.toml | 2 +- src/app/data/mod.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25d6e04..3755ccf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,6 @@ chrono = { version = "0.4", features = ["wasmbind"] } serde = { version = "1", features = ["derive"] } serde_json = "1" rusqlite = { version = "0.27" } -jq-rs = { version = "0.4", features = ["bundled"] } +jql = { version = "4", default-features = false } ureq = { version = "2", features = ["json"] } eframe = { version = "0.18", features = ["persistence"] } diff --git a/src/app/data/mod.rs b/src/app/data/mod.rs index 4e92ea6..b5f39ca 100644 --- a/src/app/data/mod.rs +++ b/src/app/data/mod.rs @@ -14,7 +14,8 @@ use self::store::SQLiteDataStore; pub enum FetchError { UreqError(ureq::Error), IoError(std::io::Error), - JqError(jq_rs::Error), + // JqError(jq_rs::Error), + JQLError(String), RusqliteError(rusqlite::Error), ParseFloatError(ParseFloatError), NoPanelWithThatIdError, @@ -26,8 +27,8 @@ impl From:: for FetchError { impl From:: for FetchError { fn from(e: std::io::Error) -> Self { FetchError::IoError(e) } } -impl From:: for FetchError { - fn from(e: jq_rs::Error) -> Self { FetchError::JqError(e) } +impl From:: for FetchError { // TODO wtf? why does JQL error as a String? + fn from(e: String) -> Self { FetchError::JQLError(e) } } impl From:: for FetchError { fn from(e: ParseFloatError) -> Self { FetchError::ParseFloatError(e) } @@ -128,14 +129,13 @@ impl Source { } pub fn fetch(url:&str, query_x:&str, query_y:&str) -> Result { - let res = ureq::get(url).call()?; - let body = res.into_string()?; + let res = ureq::get(url).call()?.into_json()?; let x : f64; if query_x.len() > 0 { - x = jq_rs::compile(query_x)?.run(&body)?.trim().parse::()?; // TODO precompile and guard with a mutex + x = jql::walker(&res, query_x)?.as_f64().unwrap(); // TODO what if it's given to us as a string? } else { x = Utc::now().timestamp() as f64; } - let y = jq_rs::compile(query_y)?.run(&body)?.trim().parse::()?; + let y = jql::walker(&res, query_y)?.as_f64().unwrap(); return Ok( Value { x, y } ); } \ No newline at end of file