Perform an `INSERT` operation on the ActiveModel # Example (Postgres) ``` # use sea_orm::{error::*, tests_cfg::*, *}; # # #[smol_potat::main] # #[cfg(feature = "mock")] # pub async fn main() -> Result<(), DbErr> { # # let db = MockDatabase::new(DbBackend::Postgres) # .append_query_results([ # [cake::Model { # id: 15, # name: "Apple Pie".to_owned(), # }
(self, db: &'a C)
| 272 | /// # } |
| 273 | /// ``` |
| 274 | async fn insert<'a, C>(self, db: &'a C) -> Result<<Self::Entity as EntityTrait>::Model, DbErr> |
| 275 | where |
| 276 | <Self::Entity as EntityTrait>::Model: IntoActiveModel<Self>, |
| 277 | Self: ActiveModelBehavior + 'a, |
| 278 | C: ConnectionTrait, |
| 279 | { |
| 280 | let am = ActiveModelBehavior::before_save(self, db, true).await?; |
| 281 | let model = <Self::Entity as EntityTrait>::insert(am) |
| 282 | .exec_with_returning(db) |
| 283 | .await?; |
| 284 | Self::after_save(model, db, true).await |
| 285 | } |
| 286 | |
| 287 | /// Perform the `UPDATE` operation on an ActiveModel |
| 288 | /// |
no test coverage detected