From 72a8e5a9134eb6f6fbfa1e87a71c9f17a0393711 Mon Sep 17 00:00:00 2001 From: makorne Date: Mon, 11 Nov 2024 15:31:52 +0700 Subject: [PATCH] Added updated_at Datetime Error: ColumnDecode { index: "\"updated_at\"", source: "mismatched types; Rust type `core::option::Option` (as SQL type `Timestamp`) is not compatible with SQL type `DateTime`" } --- example/src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/example/src/main.rs b/example/src/main.rs index f2ff96b..d56ca7d 100644 --- a/example/src/main.rs +++ b/example/src/main.rs @@ -1,3 +1,4 @@ +use std::time::SystemTime; use tracing::info; use tracing_log::log::LevelFilter; use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; @@ -18,7 +19,7 @@ async fn main() -> Result<(), Box> { assert_eq!(row.0, 2); let conn = pool.acquire().await?; - sqlx::query("CREATE TABLE test4 (id Uint64 NOT NULL, name Utf8, age UInt8 NOT NULL, description Utf8, PRIMARY KEY (id))") + sqlx::query("CREATE TABLE test4 (id Uint64 NOT NULL, name Utf8, age UInt8 NOT NULL, description Utf8, updated_at DateTime, PRIMARY KEY (id))") .execute(conn.schema()) .await?; @@ -26,7 +27,8 @@ async fn main() -> Result<(), Box> { id: 13u64, name: "test".to_string(), age: 32u8, - description: None + description: None, + updated_at: None }; let res = sqlx::query("DELETE FROM test4 where id = $id") @@ -36,7 +38,7 @@ async fn main() -> Result<(), Box> { info!("rows affected: {}", res.rows_affected()); - sqlx::query("INSERT INTO test4 (id, name, age, description) VALUES ( $arg_1, $arg_2, $age, $arg_3)") + sqlx::query("INSERT INTO test4 (id, name, age, description, updated_at) VALUES ( $arg_1, $arg_2, $age, $arg_3, CurrentUtcDate())") .bind(test_user_info.id) .bind(test_user_info.name) .bind(("age", test_user_info.age)) @@ -64,6 +66,7 @@ struct UserInfo { name: String, age: u8, description: Option, + updated_at: Option } fn init_logs() {