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