(db: &DbConn)
| 120 | } |
| 121 | |
| 122 | async fn find_one(db: &DbConn) -> Result<(), DbErr> { |
| 123 | print!("find one by primary key: "); |
| 124 | |
| 125 | let cheese: Option<cake::Model> = Cake::find_by_id(1).one(db).await?; |
| 126 | let cheese = cheese.unwrap(); |
| 127 | |
| 128 | println!(); |
| 129 | println!("{cheese:?}"); |
| 130 | println!(); |
| 131 | |
| 132 | print!("find one by name: "); |
| 133 | |
| 134 | let chocolate = Cake::find_by_name("chocolate").one(db).await?; |
| 135 | |
| 136 | println!(); |
| 137 | println!("{chocolate:?}"); |
| 138 | println!(); |
| 139 | |
| 140 | print!("find models belong to: "); |
| 141 | |
| 142 | let fruits = cheese.find_related(Fruit).all(db).await?; |
| 143 | |
| 144 | println!(); |
| 145 | for ff in fruits.iter() { |
| 146 | println!("{ff:?}\n"); |
| 147 | } |
| 148 | |
| 149 | Ok(()) |
| 150 | } |
| 151 | |
| 152 | async fn count_fruits_by_cake(db: &DbConn) -> Result<(), DbErr> { |
| 153 | #[derive(Debug, FromQueryResult)] |
no test coverage detected