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

Function create_and_update

tests/bits_tests.rs:20–61  ·  view source on GitHub ↗
(db: &DatabaseConnection)

Source from the content-addressed store, hash-verified

18}
19
20pub async fn create_and_update(db: &DatabaseConnection) -> Result<(), DbErr> {
21 let bits = bits::Model {
22 id: 1,
23 bit0: 0,
24 bit1: 1,
25 bit8: 8,
26 bit16: 16,
27 bit32: 32,
28 bit64: 64,
29 };
30
31 let res = bits.clone().into_active_model().insert(db).await?;
32
33 let model = Bits::find().one(db).await?;
34 assert_eq!(model, Some(res));
35 assert_eq!(model, Some(bits.clone()));
36
37 let res = bits::ActiveModel {
38 bit32: Set(320),
39 bit64: Set(640),
40 ..bits.clone().into_active_model()
41 }
42 .update(db)
43 .await?;
44
45 let model = Bits::find().one(db).await?;
46 assert_eq!(model, Some(res));
47 assert_eq!(
48 model,
49 Some(bits::Model {
50 id: 1,
51 bit0: 0,
52 bit1: 1,
53 bit8: 8,
54 bit16: 16,
55 bit32: 320,
56 bit64: 640,
57 })
58 );
59
60 Ok(())
61}

Callers 1

mainFunction · 0.70

Calls 4

into_active_modelMethod · 0.80
insertMethod · 0.45
oneMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected