| 17 | } |
| 18 | |
| 19 | pub async fn create_and_update(db: &DatabaseConnection) -> Result<(), DbErr> { |
| 20 | use common::features::byte_primary_key::*; |
| 21 | |
| 22 | let model = Model { |
| 23 | id: vec![1, 2, 3], |
| 24 | value: "First Row".to_owned(), |
| 25 | }; |
| 26 | |
| 27 | let res = Entity::insert(model.clone().into_active_model()) |
| 28 | .exec(db) |
| 29 | .await?; |
| 30 | |
| 31 | assert_eq!(Entity::find().one(db).await?, Some(model.clone())); |
| 32 | |
| 33 | assert_eq!(res.last_insert_id, model.id); |
| 34 | |
| 35 | let updated_active_model = ActiveModel { |
| 36 | value: Set("First Row (Updated)".to_owned()), |
| 37 | ..model.clone().into_active_model() |
| 38 | }; |
| 39 | |
| 40 | let update_res = Entity::update(updated_active_model.clone()) |
| 41 | .filter(Column::Id.eq(vec![1_u8, 2_u8, 4_u8])) // annotate it as Vec<u8> explicitly |
| 42 | .exec(db) |
| 43 | .await; |
| 44 | |
| 45 | assert_eq!(update_res, Err(DbErr::RecordNotUpdated)); |
| 46 | |
| 47 | let update_res = Entity::update(updated_active_model) |
| 48 | .filter(Column::Id.eq(vec![1_u8, 2_u8, 3_u8])) // annotate it as Vec<u8> explicitly |
| 49 | .exec(db) |
| 50 | .await?; |
| 51 | |
| 52 | assert_eq!( |
| 53 | update_res, |
| 54 | Model { |
| 55 | id: vec![1, 2, 3], |
| 56 | value: "First Row (Updated)".to_owned(), |
| 57 | } |
| 58 | ); |
| 59 | |
| 60 | assert_eq!( |
| 61 | Entity::find() |
| 62 | .filter(Column::Id.eq(vec![1_u8, 2_u8, 3_u8])) // annotate it as Vec<u8> explicitly |
| 63 | .one(db) |
| 64 | .await?, |
| 65 | Some(Model { |
| 66 | id: vec![1, 2, 3], |
| 67 | value: "First Row (Updated)".to_owned(), |
| 68 | }) |
| 69 | ); |
| 70 | |
| 71 | assert_eq!( |
| 72 | Entity::find() |
| 73 | .filter(Column::Id.eq(vec![1_u8, 2_u8, 3_u8])) // annotate it as Vec<u8> explicitly |
| 74 | .into_values::<_, Column>() |
| 75 | .one(db) |
| 76 | .await?, |