toasty_driver_integration_suite/scenarios/
upsert_models.rs1use crate::prelude::*;
2
3scenario! {
4 #[derive(Debug, toasty::Model)]
5 #[unique(tenant, slug)]
6 struct Entry {
7 #[key]
8 #[auto]
9 id: uuid::Uuid,
10
11 tenant: String,
12 slug: String,
13 value: String,
14 }
15
16 #[derive(Debug, toasty::Model)]
17 struct DefaultedItem {
18 #[key]
19 #[auto]
20 id: uuid::Uuid,
21
22 value: String,
23
24 #[default("created".to_string())]
25 created_only: String,
26
27 #[update("always".to_string())]
28 updated_always: String,
29 }
30
31 #[derive(Debug, toasty::Model)]
32 struct AssignedItem {
33 #[key]
34 #[auto]
35 id: uuid::Uuid,
36
37 #[default(0)]
38 count: i64,
39
40 #[default(Vec::<String>::new())]
41 tags: Vec<String>,
42 note: Option<String>,
43 }
44
45 async fn setup_entry(test: &mut Test) -> toasty::Db {
46 test.setup_db(models!(Entry)).await
47 }
48
49 async fn setup_defaulted_item(test: &mut Test) -> toasty::Db {
50 test.setup_db(models!(DefaultedItem)).await
51 }
52
53 async fn setup_assigned_item(test: &mut Test) -> toasty::Db {
54 test.setup_db(models!(AssignedItem)).await
55 }
56}