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

Function insert_8

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

Source from the content-addressed store, hash-verified

615
616 #[smol_potat::test]
617 async fn insert_8() -> Result<(), DbErr> {
618 use crate::{DbBackend, MockDatabase, Statement, Transaction};
619
620 mod post {
621 use crate as sea_orm;
622 use crate::entity::prelude::*;
623
624 #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
625 #[sea_orm(table_name = "posts")]
626 pub struct Model {
627 #[sea_orm(primary_key, select_as = "INTEGER", save_as = "TEXT")]
628 pub id: i32,
629 pub title: String,
630 pub text: String,
631 }
632
633 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
634 pub enum Relation {}
635
636 impl ActiveModelBehavior for ActiveModel {}
637 }
638
639 let model = post::Model {
640 id: 1,
641 title: "News wrap up 2022".into(),
642 text: "brbrbrrrbrbrbrr...".into(),
643 };
644
645 let db = MockDatabase::new(DbBackend::Postgres)
646 .append_query_results([[model.clone()]])
647 .into_connection();
648
649 post::Entity::insert(model.into_active_model())
650 .exec(&db)
651 .await?;
652
653 assert_eq!(
654 db.into_transaction_log(),
655 [Transaction::many([Statement::from_sql_and_values(
656 DbBackend::Postgres,
657 r#"INSERT INTO "posts" ("id", "title", "text") VALUES (CAST($1 AS TEXT), $2, $3) RETURNING CAST("id" AS INTEGER)"#,
658 [
659 1.into(),
660 "News wrap up 2022".into(),
661 "brbrbrrrbrbrbrr...".into(),
662 ]
663 )])]
664 );
665
666 Ok(())
667 }
668
669 #[smol_potat::test]
670 async fn insert_9() -> Result<(), DbErr> {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected