| 17 | } |
| 18 | |
| 19 | pub async fn create_transaction_log(db: &DatabaseConnection) -> Result<(), DbErr> { |
| 20 | let transaction_log = transaction_log::Model { |
| 21 | id: 1, |
| 22 | date: date!(2022 - 03 - 13), |
| 23 | time: time!(16:24:00), |
| 24 | date_time: date!(2022 - 03 - 13).with_time(time!(16:24:00)), |
| 25 | date_time_tz: date!(2022 - 03 - 13) |
| 26 | .with_time(time!(16:24:00)) |
| 27 | .assume_utc(), |
| 28 | }; |
| 29 | |
| 30 | let res = TransactionLog::insert(transaction_log.clone().into_active_model()) |
| 31 | .exec(db) |
| 32 | .await?; |
| 33 | |
| 34 | assert_eq!(transaction_log.id, res.last_insert_id); |
| 35 | assert_eq!( |
| 36 | TransactionLog::find().one(db).await?, |
| 37 | Some(transaction_log.clone()) |
| 38 | ); |
| 39 | |
| 40 | let json = TransactionLog::find().into_json().one(db).await?.unwrap(); |
| 41 | |
| 42 | #[cfg(feature = "sqlx-postgres")] |
| 43 | assert_eq!( |
| 44 | json, |
| 45 | json!({ |
| 46 | "id": 1, |
| 47 | "date": "2022-03-13", |
| 48 | "time": "16:24:00", |
| 49 | "date_time": "2022-03-13T16:24:00", |
| 50 | "date_time_tz": "2022-03-13T16:24:00Z", |
| 51 | }) |
| 52 | ); |
| 53 | |
| 54 | #[cfg(feature = "sqlx-mysql")] |
| 55 | assert_eq!( |
| 56 | json, |
| 57 | json!({ |
| 58 | "id": 1, |
| 59 | "date": "2022-03-13", |
| 60 | "time": "16:24:00", |
| 61 | "date_time": "2022-03-13T16:24:00", |
| 62 | "date_time_tz": "2022-03-13T16:24:00Z", |
| 63 | }) |
| 64 | ); |
| 65 | |
| 66 | #[cfg(feature = "sqlx-sqlite")] |
| 67 | assert_eq!( |
| 68 | json, |
| 69 | json!({ |
| 70 | "id": 1, |
| 71 | "date": "2022-03-13", |
| 72 | "time": "16:24:00.0", |
| 73 | "date_time": "2022-03-13 16:24:00.0", |
| 74 | "date_time_tz": "2022-03-13T16:24:00Z", |
| 75 | }) |
| 76 | ); |