Skip to content

Commit 890e22c

Browse files
authored
SQLite bind rust_decimal & bigdecimal as f64 (#480)
* SQLite bind `rust_decimal` & `bigdecimal` as f64 * Use expect over unwrap
1 parent 1afbde4 commit 890e22c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sea-query-binder/src/sqlx_sqlite.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,18 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::sqlite::Sqlite> for SqlxValues {
9494
args.add(uuid.map(|uuid| *uuid));
9595
}
9696
#[cfg(feature = "with-rust_decimal")]
97-
Value::Decimal(_) => {
98-
panic!("Sqlite doesn't support decimal arguments");
97+
Value::Decimal(decimal) => {
98+
use rust_decimal::prelude::ToPrimitive;
99+
args.add(
100+
decimal.map(|d| d.to_f64().expect("Fail to convert rust_decimal as f64")),
101+
);
99102
}
100103
#[cfg(feature = "with-bigdecimal")]
101-
Value::BigDecimal(_) => {
102-
panic!("Sqlite doesn't support bigdecimal arguments");
104+
Value::BigDecimal(big_decimal) => {
105+
use bigdecimal::ToPrimitive;
106+
args.add(
107+
big_decimal.map(|d| d.to_f64().expect("Fail to convert bigdecimal as f64")),
108+
);
103109
}
104110
#[cfg(feature = "with-json")]
105111
Value::Json(j) => {

0 commit comments

Comments
 (0)