Skip to content

Commit

Permalink
fix(sql): Encode JSON numbers as f64 to fix JSON_EXTRACT queries (#797)
Browse files Browse the repository at this point in the history
Signed-off-by: Mitchell van der Hoeff <[email protected]>
  • Loading branch information
mitchelljustin authored Dec 6, 2023
1 parent 0e3e3d4 commit f4b2674
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-number-query-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sql": patch
---

Encode JSON number query params as f64 to fix JSON_EXTRACT queries on SQLite
4 changes: 4 additions & 0 deletions plugins/sql/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ async fn execute(
query = query.bind(None::<JsonValue>);
} 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);
}
Expand Down Expand Up @@ -240,6 +242,8 @@ async fn select(
query = query.bind(None::<JsonValue>);
} 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);
}
Expand Down

0 comments on commit f4b2674

Please sign in to comment.