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

Function insert_9

src/query/insert.rs:670–737  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

668
669 #[smol_potat::test]
670 async fn insert_9() -> Result<(), DbErr> {
671 use crate::{DbBackend, MockDatabase, MockExecResult, Statement, Transaction};
672
673 mod post {
674 use crate as sea_orm;
675 use crate::entity::prelude::*;
676
677 #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
678 #[sea_orm(table_name = "posts")]
679 pub struct Model {
680 #[sea_orm(
681 primary_key,
682 auto_increment = false,
683 select_as = "INTEGER",
684 save_as = "TEXT"
685 )]
686 pub id_primary: i32,
687 #[sea_orm(
688 primary_key,
689 auto_increment = false,
690 select_as = "INTEGER",
691 save_as = "TEXT"
692 )]
693 pub id_secondary: i32,
694 pub title: String,
695 pub text: String,
696 }
697
698 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
699 pub enum Relation {}
700
701 impl ActiveModelBehavior for ActiveModel {}
702 }
703
704 let model = post::Model {
705 id_primary: 1,
706 id_secondary: 1001,
707 title: "News wrap up 2022".into(),
708 text: "brbrbrrrbrbrbrr...".into(),
709 };
710
711 let db = MockDatabase::new(DbBackend::Postgres)
712 .append_exec_results([MockExecResult {
713 last_insert_id: 1,
714 rows_affected: 1,
715 }])
716 .into_connection();
717
718 post::Entity::insert(model.into_active_model())
719 .exec(&db)
720 .await?;
721
722 assert_eq!(
723 db.into_transaction_log(),
724 [Transaction::many([Statement::from_sql_and_values(
725 DbBackend::Postgres,
726 r#"INSERT INTO "posts" ("id_primary", "id_secondary", "title", "text") VALUES (CAST($1 AS TEXT), CAST($2 AS TEXT), $3, $4) RETURNING CAST("id_primary" AS INTEGER), CAST("id_secondary" AS INTEGER)"#,
727 [

Callers

nothing calls this directly

Calls 5

into_connectionMethod · 0.80
append_exec_resultsMethod · 0.80
into_active_modelMethod · 0.80
newFunction · 0.50
execMethod · 0.45

Tested by

no test coverage detected