diff --git a/.changes/fix-number-query-params.md b/.changes/fix-number-query-params.md new file mode 100644 index 000000000..2785898fa --- /dev/null +++ b/.changes/fix-number-query-params.md @@ -0,0 +1,5 @@ +--- +"sql": patch +--- + +Encode JSON number query params as f64 to fix JSON_EXTRACT queries on SQLite diff --git a/plugins/sql/src/plugin.rs b/plugins/sql/src/plugin.rs index 8d5243455..aa6ec5f53 100644 --- a/plugins/sql/src/plugin.rs +++ b/plugins/sql/src/plugin.rs @@ -211,6 +211,8 @@ async fn execute( query = query.bind(None::); } else if value.is_string() { query = query.bind(value.as_str().unwrap().to_owned()) + } else if let Some(number) = value.as_number() { + query = query.bind(number.as_f64().unwrap_or_default()) } else { query = query.bind(value); } @@ -240,6 +242,8 @@ async fn select( query = query.bind(None::); } else if value.is_string() { query = query.bind(value.as_str().unwrap().to_owned()) + } else if let Some(number) = value.as_number() { + query = query.bind(number.as_f64().unwrap_or_default()) } else { query = query.bind(value); }