Fix build error from rust_decimal

This commit is contained in:
Chris Tsang 2021-07-08 01:26:42 +08:00
parent dbe950e628
commit 40dd5e7da7
2 changed files with 8 additions and 27 deletions

View File

@ -35,6 +35,7 @@ async-stream = { version = "^0.3" }
chrono = { version = "^0", optional = true } chrono = { version = "^0", optional = true }
futures = { version = "^0.3" } futures = { version = "^0.3" }
futures-util = { version = "^0.3" } futures-util = { version = "^0.3" }
rust_decimal = { version = "^1", optional = true }
sea-query = { version = "^0.12" } sea-query = { version = "^0.12" }
sea-orm-macros = { path = "sea-orm-macros", optional = true } sea-orm-macros = { path = "sea-orm-macros", optional = true }
serde = { version = "^1.0", features = [ "derive" ] } serde = { version = "^1.0", features = [ "derive" ] }
@ -45,6 +46,7 @@ serde_json = { version = "^1", optional = true }
[dev-dependencies] [dev-dependencies]
async-std = { version = "^1.9", features = [ "attributes" ] } async-std = { version = "^1.9", features = [ "attributes" ] }
maplit = { version = "^1" } maplit = { version = "^1" }
rust_decimal_macros = { version = "^1" }
sea-orm = { path = ".", features = ["sqlx-sqlite", "sqlx-json", "sqlx-chrono", "sqlx-decimal", "runtime-async-std-native-tls"] } sea-orm = { path = ".", features = ["sqlx-sqlite", "sqlx-json", "sqlx-chrono", "sqlx-decimal", "runtime-async-std-native-tls"] }
[features] [features]
@ -54,7 +56,7 @@ macros = [ "sea-orm-macros" ]
mock = [] mock = []
with-json = [ "serde_json", "sea-query/with-json" ] with-json = [ "serde_json", "sea-query/with-json" ]
with-chrono = [ "chrono", "sea-query/with-chrono" ] with-chrono = [ "chrono", "sea-query/with-chrono" ]
with-rust_decimal = [ "sea-query/with-rust_decimal" ] with-rust_decimal = [ "rust_decimal", "sea-query/with-rust_decimal" ]
sqlx-dep = [ "sqlx" ] sqlx-dep = [ "sqlx" ]
sqlx-json = [ "sqlx/json", "with-json" ] sqlx-json = [ "sqlx/json", "with-json" ]
sqlx-chrono = [ "sqlx/chrono", "with-chrono" ] sqlx-chrono = [ "sqlx/chrono", "with-chrono" ]

View File

@ -1,5 +1,4 @@
use crate::DbErr; use crate::DbErr;
use rust_decimal::prelude::*;
use std::fmt; use std::fmt;
#[derive(Debug)] #[derive(Debug)]
@ -47,25 +46,6 @@ impl fmt::Debug for QueryResultRow {
} }
// TryGetable // // TryGetable //
impl TryGetable for Decimal {
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr> {
let column = format!("{}{}", pre, col);
match &res.row {
#[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => {
use sqlx::Row;
row.try_get(column.as_str())
.map_err(crate::sqlx_error_to_query_err)
}
#[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(_) => {
panic!("{} unsupported by sqlx-sqlite", stringify!($type))
}
#[cfg(feature = "mock")]
QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?),
}
}
}
macro_rules! try_getable_all { macro_rules! try_getable_all {
( $type: ty ) => { ( $type: ty ) => {
@ -76,14 +56,12 @@ macro_rules! try_getable_all {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => { QueryResultRow::SqlxMySql(row) => {
use sqlx::Row; use sqlx::Row;
row.try_get(column.as_str()) row.try_get(column.as_str()).map_err(crate::sqlx_error_to_query_err)
.map_err(crate::sqlx_error_to_query_err)
} }
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(row) => { QueryResultRow::SqlxSqlite(row) => {
use sqlx::Row; use sqlx::Row;
row.try_get(column.as_str()) row.try_get(column.as_str()).map_err(crate::sqlx_error_to_query_err)
.map_err(crate::sqlx_error_to_query_err)
} }
#[cfg(feature = "mock")] #[cfg(feature = "mock")]
QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?), QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?),
@ -131,8 +109,7 @@ macro_rules! try_getable_mysql {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => { QueryResultRow::SqlxMySql(row) => {
use sqlx::Row; use sqlx::Row;
row.try_get(column.as_str()) row.try_get(column.as_str()).map_err(crate::sqlx_error_to_query_err)
.map_err(crate::sqlx_error_to_query_err)
} }
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(_) => { QueryResultRow::SqlxSqlite(_) => {
@ -183,3 +160,5 @@ try_getable_mysql!(u64);
try_getable_all!(f32); try_getable_all!(f32);
try_getable_all!(f64); try_getable_all!(f64);
try_getable_all!(String); try_getable_all!(String);
#[cfg(feature = "with-rust_decimal")]
try_getable_mysql!(rust_decimal::Decimal);