MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / insert

Method insert

src/entity/active_model.rs:274–285  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 ///

Callers 1

saveMethod · 0.45

Calls 1

exec_with_returningMethod · 0.45

Tested by

no test coverage detected