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

Function insert_active_enum

tests/active_enum_tests.rs:35–265  ·  view source on GitHub ↗
(db: &DatabaseConnection)

Source from the content-addressed store, hash-verified

33}
34
35pub async fn insert_active_enum(db: &DatabaseConnection) -> Result<(), DbErr> {
36 use active_enum::*;
37
38 let model = Model {
39 id: 1,
40 category: None,
41 color: None,
42 tea: None,
43 };
44
45 assert_eq!(
46 model,
47 ActiveModel {
48 category: Set(None),
49 color: Set(None),
50 tea: Set(None),
51 ..Default::default()
52 }
53 .insert(db)
54 .await?
55 );
56 assert_eq!(model, Entity::find().one(db).await?.unwrap());
57 assert_eq!(
58 model,
59 Entity::find()
60 .filter(Column::Id.is_not_null())
61 .filter(Column::Category.is_null())
62 .filter(Column::Color.is_null())
63 .filter(Column::Tea.is_null())
64 .one(db)
65 .await?
66 .unwrap()
67 );
68
69 let _ = ActiveModel {
70 category: Set(Some(Category::Big)),
71 color: Set(Some(Color::Black)),
72 tea: Set(Some(Tea::EverydayTea)),
73 ..model.into_active_model()
74 }
75 .save(db)
76 .await?;
77
78 let model = Entity::find().one(db).await?.unwrap();
79 assert_eq!(
80 model,
81 Model {
82 id: 1,
83 category: Some(Category::Big),
84 color: Some(Color::Black),
85 tea: Some(Tea::EverydayTea),
86 }
87 );
88 assert_eq!(
89 model,
90 Entity::find()
91 .filter(Column::Id.eq(1))
92 .filter(Column::Category.eq(Category::Big))

Callers 1

mainFunction · 0.85

Calls 6

saveMethod · 0.80
into_active_modelMethod · 0.80
unwrapMethod · 0.80
filterMethod · 0.80
oneMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected