More examples
This commit is contained in:
parent
890464f913
commit
1a52e64572
@ -2,13 +2,45 @@ use crate::*;
|
||||
use sea_orm::{entity::*, query::*, Database};
|
||||
|
||||
pub async fn all_about_operation(db: &Database) -> Result<(), ExecErr> {
|
||||
insert_and_update(db).await?;
|
||||
|
||||
println!("===== =====\n");
|
||||
|
||||
save_active_model(db).await?;
|
||||
|
||||
println!("===== =====\n");
|
||||
|
||||
save_custom_active_model(db).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn insert_and_update(db: &Database) -> Result<(), ExecErr> {
|
||||
let pear = fruit::ActiveModel {
|
||||
name: Val::set("pear".to_owned()),
|
||||
..Default::default()
|
||||
};
|
||||
let res = fruit::Entity::insert(pear).exec(db).await?;
|
||||
|
||||
println!();
|
||||
println!("Inserted: {:?}\n", res);
|
||||
|
||||
let pear = fruit::Entity::find_by(res.last_insert_id).one(db).await.map_err(|_| ExecErr)?;
|
||||
|
||||
println!();
|
||||
println!("Pear: {:?}\n", pear);
|
||||
|
||||
let mut pear: fruit::ActiveModel = pear.into();
|
||||
pear.name = Val::set("Sweet pear".to_owned());
|
||||
|
||||
let res = fruit::Entity::update(pear).exec(db).await?;
|
||||
|
||||
println!();
|
||||
println!("Updated: {:?}\n", res);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn save_active_model(db: &Database) -> Result<(), ExecErr> {
|
||||
let banana = fruit::ActiveModel {
|
||||
name: Val::set("banana".to_owned()),
|
||||
|
Loading…
x
Reference in New Issue
Block a user