()
| 286 | |
| 287 | #[sea_orm_macros::test] |
| 288 | pub async fn group_by() { |
| 289 | let ctx = TestContext::new("test_group_by").await; |
| 290 | create_tables(&ctx.db).await.unwrap(); |
| 291 | |
| 292 | let bakery = bakery::ActiveModel { |
| 293 | name: Set("SeaSide Bakery".to_owned()), |
| 294 | profit_margin: Set(10.4), |
| 295 | ..Default::default() |
| 296 | } |
| 297 | .insert(&ctx.db) |
| 298 | .await |
| 299 | .expect("could not insert bakery"); |
| 300 | |
| 301 | let customer_kate = customer::ActiveModel { |
| 302 | name: Set("Kate".to_owned()), |
| 303 | ..Default::default() |
| 304 | } |
| 305 | .insert(&ctx.db) |
| 306 | .await |
| 307 | .expect("could not insert customer"); |
| 308 | |
| 309 | let kate_order_1 = order::ActiveModel { |
| 310 | bakery_id: Set(bakery.id), |
| 311 | customer_id: Set(customer_kate.id), |
| 312 | total: Set(rust_dec(99.95)), |
| 313 | placed_at: Set(Utc::now().naive_utc()), |
| 314 | |
| 315 | ..Default::default() |
| 316 | } |
| 317 | .insert(&ctx.db) |
| 318 | .await |
| 319 | .expect("could not insert order"); |
| 320 | |
| 321 | let kate_order_2 = order::ActiveModel { |
| 322 | bakery_id: Set(bakery.id), |
| 323 | customer_id: Set(customer_kate.id), |
| 324 | total: Set(rust_dec(200.00)), |
| 325 | placed_at: Set(Utc::now().naive_utc()), |
| 326 | |
| 327 | ..Default::default() |
| 328 | } |
| 329 | .insert(&ctx.db) |
| 330 | .await |
| 331 | .expect("could not insert order"); |
| 332 | |
| 333 | #[cfg(any(feature = "sqlx-postgres"))] |
| 334 | type Type = i64; |
| 335 | #[cfg(not(any(feature = "sqlx-postgres")))] |
| 336 | type Type = i32; |
| 337 | |
| 338 | #[derive(Debug, FromQueryResult)] |
| 339 | struct SelectResult { |
| 340 | name: String, |
| 341 | number_orders: Option<Type>, |
| 342 | total_spent: Option<Decimal>, |
| 343 | min_spent: Option<Decimal>, |
| 344 | max_spent: Option<Decimal>, |
| 345 | } |
nothing calls this directly
no test coverage detected