MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / group_by

Function group_by

tests/relational_tests.rs:288–379  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

286
287#[sea_orm_macros::test]
288pub 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 }

Callers

nothing calls this directly

Calls 13

rust_decFunction · 0.85
unwrapMethod · 0.80
group_byMethod · 0.80
column_asMethod · 0.80
columnMethod · 0.80
select_onlyMethod · 0.80
left_joinMethod · 0.80
countMethod · 0.80
newFunction · 0.50
create_tablesFunction · 0.50
insertMethod · 0.45
oneMethod · 0.45

Tested by

no test coverage detected