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

Function init_1

tests/common/bakery_chain/seed_data.rs:5–100  ·  view source on GitHub ↗
(ctx: &TestContext, link: bool)

Source from the content-addressed store, hash-verified

3use sea_orm::{prelude::*, NotSet, Set};
4
5pub async fn init_1(ctx: &TestContext, link: bool) {
6 bakery::Entity::insert(bakery::ActiveModel {
7 id: Set(42),
8 name: Set("cool little bakery".to_string()),
9 profit_margin: Set(4.1),
10 })
11 .exec(&ctx.db)
12 .await
13 .expect("insert succeeds");
14
15 cake::Entity::insert(cake::ActiveModel {
16 id: Set(13),
17 name: Set("Cheesecake".to_owned()),
18 price: Set(2.into()),
19 bakery_id: Set(if link { Some(42) } else { None }),
20 gluten_free: Set(false),
21 ..Default::default()
22 })
23 .exec(&ctx.db)
24 .await
25 .expect("insert succeeds");
26
27 cake::Entity::insert(cake::ActiveModel {
28 id: Set(15),
29 name: Set("Chocolate".to_owned()),
30 price: Set(3.into()),
31 bakery_id: Set(if link { Some(42) } else { None }),
32 gluten_free: Set(true),
33 ..Default::default()
34 })
35 .exec(&ctx.db)
36 .await
37 .expect("insert succeeds");
38
39 baker::Entity::insert(baker::ActiveModel {
40 id: Set(22),
41 name: Set("Master Baker".to_owned()),
42 contact_details: Set(Json::Null),
43 bakery_id: Set(if link { Some(42) } else { None }),
44 })
45 .exec(&ctx.db)
46 .await
47 .expect("insert succeeds");
48
49 if link {
50 cakes_bakers::Entity::insert(cakes_bakers::ActiveModel {
51 cake_id: Set(13),
52 baker_id: Set(22),
53 })
54 .exec(&ctx.db)
55 .await
56 .expect("insert succeeds");
57
58 customer::Entity::insert(customer::ActiveModel {
59 id: Set(11),
60 name: Set("Bob".to_owned()),
61 notes: Set(Some("Sweet tooth".to_owned())),
62 })

Calls 1

execMethod · 0.45