Update example
This commit is contained in:
parent
7e3bc1c7b3
commit
5d16222108
@ -20,12 +20,12 @@ pub async fn insert_and_update(db: &DbConn) -> Result<(), ExecErr> {
|
||||
name: Set("pear".to_owned()),
|
||||
..Default::default()
|
||||
};
|
||||
let res = Fruit::insert(pear).exec(db).await?;
|
||||
let res: InsertResult = Fruit::insert(pear).exec(db).await?;
|
||||
|
||||
println!();
|
||||
println!("Inserted: {:?}\n", res);
|
||||
println!("Inserted: last_insert_id = {}\n", res.last_insert_id);
|
||||
|
||||
let pear = Fruit::find_by_id(res.last_insert_id)
|
||||
let pear: Option<fruit::Model> = Fruit::find_by_id(res.last_insert_id)
|
||||
.one(db)
|
||||
.await
|
||||
.map_err(|_| ExecErr)?;
|
||||
@ -36,10 +36,10 @@ pub async fn insert_and_update(db: &DbConn) -> Result<(), ExecErr> {
|
||||
let mut pear: fruit::ActiveModel = pear.unwrap().into();
|
||||
pear.name = Set("Sweet pear".to_owned());
|
||||
|
||||
let res = Fruit::update(pear).exec(db).await?;
|
||||
let pear: fruit::ActiveModel = Fruit::update(pear).exec(db).await?;
|
||||
|
||||
println!();
|
||||
println!("Updated: {:?}\n", res);
|
||||
println!("Updated: {:?}\n", pear);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ pub async fn all_about_select(db: &DbConn) -> Result<(), QueryErr> {
|
||||
async fn find_all(db: &DbConn) -> Result<(), QueryErr> {
|
||||
print!("find all cakes: ");
|
||||
|
||||
let cakes = Cake::find().all(db).await?;
|
||||
let cakes: Vec<cake::Model> = Cake::find().all(db).await?;
|
||||
|
||||
println!();
|
||||
for cc in cakes.iter() {
|
||||
@ -105,7 +105,7 @@ async fn find_one(db: &DbConn) -> Result<(), QueryErr> {
|
||||
|
||||
print!("find models belong to: ");
|
||||
|
||||
let fruits = cheese.find_fruit().all(db).await?;
|
||||
let fruits = cheese.find_related(Fruit).all(db).await?;
|
||||
|
||||
println!();
|
||||
for ff in fruits.iter() {
|
||||
@ -144,7 +144,7 @@ async fn count_fruits_by_cake(db: &DbConn) -> Result<(), QueryErr> {
|
||||
async fn find_many_to_many(db: &DbConn) -> Result<(), QueryErr> {
|
||||
print!("find cakes and fillings: ");
|
||||
|
||||
let both = Cake::find()
|
||||
let both: Vec<(cake::Model, Vec<filling::Model>)> = Cake::find()
|
||||
.left_join_and_select_with(Filling)
|
||||
.all(db)
|
||||
.await?;
|
||||
|
@ -3,6 +3,7 @@ mod driver;
|
||||
pub mod entity;
|
||||
mod executor;
|
||||
pub mod query;
|
||||
#[doc(hidden)]
|
||||
pub mod tests_cfg;
|
||||
mod util;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user