Skip to content

Commit

Permalink
Fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Jul 7, 2021
1 parent 2ab5823 commit b0c9eee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/driver/sqlx_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ macro_rules! bind_params_sqlx_sqlite {
} else if value.is_date_time() {
query.bind(value.as_ref_date_time())
} else if value.is_decimal() {
use sea_query::rust_decimal::ToPrimitive;
query.bind(value.as_ref_decimal().to_f64().unwrap())
query.bind(value.decimal_to_f64())
} else if value.is_uuid() {
query.bind(value.as_ref_uuid())
} else {
Expand Down
17 changes: 11 additions & 6 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ use std::str::from_utf8;
use chrono::NaiveDateTime;

#[cfg(feature = "with-rust_decimal")]
use ::rust_decimal::Decimal;
#[cfg(feature = "with-rust_decimal")]
pub mod rust_decimal {
pub use rust_decimal::prelude::ToPrimitive;
}
use rust_decimal::Decimal;

#[cfg(feature = "with-uuid")]
use uuid::Uuid;
Expand Down Expand Up @@ -291,10 +287,19 @@ impl Value {
_ => panic!("not Value::Decimal"),
}
}
#[cfg(feature = "with-rust_decimal")]
pub fn decimal_to_f64(&self) -> f64 {
use rust_decimal::prelude::ToPrimitive;
self.as_ref_decimal().to_f64().unwrap()
}
#[cfg(not(feature = "with-rust_decimal"))]
pub fn as_ref_decimal(&self) -> &bool {
panic!("not Value::Decimal")
}
#[cfg(not(feature = "with-rust_decimal"))]
pub fn decimal_to_f64(&self) -> f64 {
0.0
}
}

impl Value {
Expand Down Expand Up @@ -454,7 +459,7 @@ pub fn sea_value_to_json_value(v: &Value) -> Json {
Value::DateTime(v) => v.format("%Y-%m-%d %H:%M:%S").to_string().into(),
#[cfg(feature = "with-rust_decimal")]
Value::Decimal(v) => {
use self::rust_decimal::ToPrimitive;
use rust_decimal::prelude::ToPrimitive;
v.as_ref().to_f64().unwrap().into()
},
#[cfg(feature = "with-uuid")]
Expand Down

0 comments on commit b0c9eee

Please sign in to comment.