(db: &DbConn)
| 150 | } |
| 151 | |
| 152 | async fn count_fruits_by_cake(db: &DbConn) -> Result<(), DbErr> { |
| 153 | #[derive(Debug, FromQueryResult)] |
| 154 | struct SelectResult { |
| 155 | name: String, |
| 156 | num_of_fruits: i32, |
| 157 | } |
| 158 | |
| 159 | print!("count fruits by cake: "); |
| 160 | |
| 161 | let select = Cake::find() |
| 162 | .left_join(Fruit) |
| 163 | .select_only() |
| 164 | .column(cake::Column::Name) |
| 165 | .column_as(fruit::Column::Id.count(), "num_of_fruits") |
| 166 | .group_by(cake::Column::Name); |
| 167 | |
| 168 | let results = select.into_model::<SelectResult>().all(db).await?; |
| 169 | |
| 170 | println!(); |
| 171 | for rr in results.iter() { |
| 172 | println!("{rr:?}\n"); |
| 173 | } |
| 174 | |
| 175 | Ok(()) |
| 176 | } |
| 177 | |
| 178 | async fn find_many_to_many(db: &DbConn) -> Result<(), DbErr> { |
| 179 | print!("find cakes and fillings: "); |
no test coverage detected