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

Function create_and_update_pi

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

Source from the content-addressed store, hash-verified

18}
19
20pub async fn create_and_update_pi(db: &DatabaseConnection) -> Result<(), DbErr> {
21 fn trunc_dec_scale(mut model: pi::Model) -> pi::Model {
22 model.decimal = model.decimal.trunc_with_scale(3);
23 model.big_decimal = model.big_decimal.with_scale(3);
24 model.decimal_opt = model.decimal_opt.map(|decimal| decimal.trunc_with_scale(3));
25 model.big_decimal_opt = model
26 .big_decimal_opt
27 .map(|big_decimal| big_decimal.with_scale(3));
28 model
29 }
30
31 let pi = trunc_dec_scale(pi::Model {
32 id: 1,
33 decimal: rust_dec(3.1415926536),
34 big_decimal: BigDecimal::from_str("3.1415926536").unwrap(),
35 decimal_opt: None,
36 big_decimal_opt: None,
37 });
38
39 let res = trunc_dec_scale(pi.clone().into_active_model().insert(db).await?);
40
41 let model = trunc_dec_scale(Pi::find().one(db).await?.unwrap());
42 assert_eq!(model, res);
43 assert_eq!(model, pi.clone());
44
45 let res = trunc_dec_scale(
46 pi::ActiveModel {
47 decimal_opt: Set(Some(rust_dec(3.1415926536))),
48 big_decimal_opt: Set(Some(BigDecimal::from_str("3.1415926536").unwrap())),
49 ..pi.clone().into_active_model()
50 }
51 .update(db)
52 .await?,
53 );
54
55 let model = trunc_dec_scale(Pi::find().one(db).await?.unwrap());
56 assert_eq!(model, res);
57 assert_eq!(
58 model,
59 trunc_dec_scale(pi::Model {
60 id: 1,
61 decimal: rust_dec(3.1415926536),
62 big_decimal: BigDecimal::from_str("3.1415926536").unwrap(),
63 decimal_opt: Some(rust_dec(3.1415926536)),
64 big_decimal_opt: Some(BigDecimal::from_str("3.1415926536").unwrap()),
65 })
66 );
67
68 Ok(())
69}

Callers 1

mainFunction · 0.85

Calls 7

trunc_dec_scaleFunction · 0.85
rust_decFunction · 0.85
unwrapMethod · 0.80
into_active_modelMethod · 0.80
insertMethod · 0.45
oneMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected