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

Function find_one

examples/basic/src/select.rs:122–150  ·  view source on GitHub ↗
(db: &DbConn)

Source from the content-addressed store, hash-verified

120}
121
122async 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
152async fn count_fruits_by_cake(db: &DbConn) -> Result<(), DbErr> {
153 #[derive(Debug, FromQueryResult)]

Callers 1

all_about_selectFunction · 0.85

Calls 4

unwrapMethod · 0.80
oneMethod · 0.45
allMethod · 0.45
find_relatedMethod · 0.45

Tested by

no test coverage detected