Merge pull request #379 from SeaQL/issues/344-temp-fix
Temporary Fix: Handling MySQL & SQLite timestamp columns
This commit is contained in:
commit
b3310e64dd
@ -30,7 +30,7 @@ futures-util = { version = "^0.3" }
|
|||||||
log = { version = "^0.4", optional = true }
|
log = { version = "^0.4", optional = true }
|
||||||
rust_decimal = { version = "^1", optional = true }
|
rust_decimal = { version = "^1", optional = true }
|
||||||
sea-orm-macros = { version = "^0.4.1", path = "sea-orm-macros", optional = true }
|
sea-orm-macros = { version = "^0.4.1", path = "sea-orm-macros", optional = true }
|
||||||
sea-query = { version = "^0.19.1", features = ["thread-safe"] }
|
sea-query = { version = "^0.19.4", features = ["thread-safe"] }
|
||||||
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
|
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
|
||||||
serde = { version = "^1.0", features = ["derive"] }
|
serde = { version = "^1.0", features = ["derive"] }
|
||||||
serde_json = { version = "^1", optional = true }
|
serde_json = { version = "^1", optional = true }
|
||||||
|
@ -199,15 +199,20 @@ macro_rules! try_getable_mysql {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! try_getable_postgres {
|
macro_rules! try_getable_date_time {
|
||||||
( $type: ty ) => {
|
( $type: ty ) => {
|
||||||
impl TryGetable for $type {
|
impl TryGetable for $type {
|
||||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
|
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
|
||||||
let _column = format!("{}{}", pre, col);
|
let _column = format!("{}{}", pre, col);
|
||||||
match &res.row {
|
match &res.row {
|
||||||
#[cfg(feature = "sqlx-mysql")]
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
QueryResultRow::SqlxMySql(_) => {
|
QueryResultRow::SqlxMySql(row) => {
|
||||||
panic!("{} unsupported by sqlx-mysql", stringify!($type))
|
use chrono::{DateTime, Utc};
|
||||||
|
use sqlx::Row;
|
||||||
|
row.try_get::<Option<DateTime<Utc>>, _>(_column.as_str())
|
||||||
|
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))
|
||||||
|
.and_then(|opt| opt.ok_or(TryGetError::Null))
|
||||||
|
.map(|v| v.into())
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
QueryResultRow::SqlxPostgres(row) => {
|
QueryResultRow::SqlxPostgres(row) => {
|
||||||
@ -217,8 +222,13 @@ macro_rules! try_getable_postgres {
|
|||||||
.and_then(|opt| opt.ok_or(TryGetError::Null))
|
.and_then(|opt| opt.ok_or(TryGetError::Null))
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-sqlite")]
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
QueryResultRow::SqlxSqlite(_) => {
|
QueryResultRow::SqlxSqlite(row) => {
|
||||||
panic!("{} unsupported by sqlx-sqlite", stringify!($type))
|
use chrono::{DateTime, Utc};
|
||||||
|
use sqlx::Row;
|
||||||
|
row.try_get::<Option<DateTime<Utc>>, _>(_column.as_str())
|
||||||
|
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))
|
||||||
|
.and_then(|opt| opt.ok_or(TryGetError::Null))
|
||||||
|
.map(|v| v.into())
|
||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
@ -259,7 +269,7 @@ try_getable_all!(chrono::NaiveTime);
|
|||||||
try_getable_all!(chrono::NaiveDateTime);
|
try_getable_all!(chrono::NaiveDateTime);
|
||||||
|
|
||||||
#[cfg(feature = "with-chrono")]
|
#[cfg(feature = "with-chrono")]
|
||||||
try_getable_postgres!(chrono::DateTime<chrono::FixedOffset>);
|
try_getable_date_time!(chrono::DateTime<chrono::FixedOffset>);
|
||||||
|
|
||||||
#[cfg(feature = "with-rust_decimal")]
|
#[cfg(feature = "with-rust_decimal")]
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
|
@ -4,7 +4,11 @@ pub use common::{features::*, setup::*, TestContext};
|
|||||||
use sea_orm::{entity::prelude::*, DatabaseConnection, IntoActiveModel};
|
use sea_orm::{entity::prelude::*, DatabaseConnection, IntoActiveModel};
|
||||||
|
|
||||||
#[sea_orm_macros::test]
|
#[sea_orm_macros::test]
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(any(
|
||||||
|
feature = "sqlx-mysql",
|
||||||
|
feature = "sqlx-sqlite",
|
||||||
|
feature = "sqlx-postgres"
|
||||||
|
))]
|
||||||
async fn main() -> Result<(), DbErr> {
|
async fn main() -> Result<(), DbErr> {
|
||||||
let ctx = TestContext::new("bakery_chain_schema_timestamp_tests").await;
|
let ctx = TestContext::new("bakery_chain_schema_timestamp_tests").await;
|
||||||
create_tables(&ctx.db).await?;
|
create_tables(&ctx.db).await?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user