Hotfix - Postgres types
This commit is contained in:
parent
9b61e22ba9
commit
d5447bca88
@ -1,4 +1,4 @@
|
|||||||
use crate::DbErr;
|
use crate::{debug_print, DbErr};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use serde_json::Value as Json;
|
use serde_json::Value as Json;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@ -92,7 +92,10 @@ macro_rules! try_getable_all {
|
|||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
match row.try_get(column.as_str()) {
|
match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
@ -100,7 +103,10 @@ macro_rules! try_getable_all {
|
|||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
match row.try_get(column.as_str()) {
|
match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-sqlite")]
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
@ -108,13 +114,19 @@ macro_rules! try_getable_all {
|
|||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
match row.try_get(column.as_str()) {
|
match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
QueryResultRow::Mock(row) => match row.try_get(column.as_str()) {
|
QueryResultRow::Mock(row) => match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,7 +171,10 @@ macro_rules! try_getable_unsigned {
|
|||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
match row.try_get(column.as_str()) {
|
match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
@ -171,13 +186,19 @@ macro_rules! try_getable_unsigned {
|
|||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
match row.try_get(column.as_str()) {
|
match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
QueryResultRow::Mock(row) => match row.try_get(column.as_str()) {
|
QueryResultRow::Mock(row) => match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,7 +241,10 @@ macro_rules! try_getable_mysql {
|
|||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
match row.try_get(column.as_str()) {
|
match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
@ -234,7 +258,10 @@ macro_rules! try_getable_mysql {
|
|||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
QueryResultRow::Mock(row) => match row.try_get(column.as_str()) {
|
QueryResultRow::Mock(row) => match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,7 +336,10 @@ impl TryGetable for Option<Decimal> {
|
|||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
match row.try_get(column.as_str()) {
|
match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
@ -317,7 +347,10 @@ impl TryGetable for Option<Decimal> {
|
|||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
match row.try_get(column.as_str()) {
|
match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-sqlite")]
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
@ -325,13 +358,19 @@ impl TryGetable for Option<Decimal> {
|
|||||||
let result: Result<Decimal, _> = TryGetable::try_get(res, pre, col);
|
let result: Result<Decimal, _> = TryGetable::try_get(res, pre, col);
|
||||||
match result {
|
match result {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
QueryResultRow::Mock(row) => match row.try_get(column.as_str()) {
|
QueryResultRow::Mock(row) => match row.try_get(column.as_str()) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(v) => Ok(Some(v)),
|
||||||
Err(_) => Ok(None),
|
Err(e) => {
|
||||||
|
debug_print!("{:#?}", e.to_string());
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ pub async fn group_by() {
|
|||||||
#[derive(Debug, FromQueryResult)]
|
#[derive(Debug, FromQueryResult)]
|
||||||
struct SelectResult {
|
struct SelectResult {
|
||||||
name: String,
|
name: String,
|
||||||
number_orders: Option<i32>,
|
number_orders: Option<i64>,
|
||||||
total_spent: Option<Decimal>,
|
total_spent: Option<Decimal>,
|
||||||
min_spent: Option<Decimal>,
|
min_spent: Option<Decimal>,
|
||||||
max_spent: Option<Decimal>,
|
max_spent: Option<Decimal>,
|
||||||
|
@ -130,10 +130,15 @@ async fn init_setup(db: &DatabaseConnection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model> {
|
async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model> {
|
||||||
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
|
type Type = i64;
|
||||||
|
#[cfg(not(feature = "sqlx-postgres"))]
|
||||||
|
type Type = Decimal;
|
||||||
|
|
||||||
#[derive(Debug, FromQueryResult)]
|
#[derive(Debug, FromQueryResult)]
|
||||||
struct SelectResult {
|
struct SelectResult {
|
||||||
id: i32,
|
id: i32,
|
||||||
cakes_sold_opt: Option<Decimal>,
|
cakes_sold_opt: Option<Type>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -174,13 +179,13 @@ async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model>
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|b| LeastSalesBakerResult {
|
.map(|b| LeastSalesBakerResult {
|
||||||
id: b.id.clone(),
|
id: b.id.clone(),
|
||||||
cakes_sold: b.cakes_sold_opt.unwrap_or(dec!(0)),
|
cakes_sold: b.cakes_sold_opt.unwrap_or_default().into(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
results.sort_by(|a, b| b.cakes_sold.cmp(&a.cakes_sold));
|
results.sort_by(|a, b| b.cakes_sold.cmp(&a.cakes_sold));
|
||||||
|
|
||||||
Baker::find_by_id(results.last().unwrap().id)
|
Baker::find_by_id(results.last().unwrap().id as i64)
|
||||||
.one(db)
|
.one(db)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user