toasty_driver_integration_suite/tests/
key_unsigned.rs

1use crate::prelude::*;
2
3/// u8 as a manually-assigned primary key.
4#[driver_test]
5pub async fn key_u8(t: &mut Test) -> Result<()> {
6    #[derive(Debug, toasty::Model)]
7    struct Item {
8        #[key]
9        id: u8,
10        val: String,
11    }
12
13    let mut db = t.setup_db(models!(Item)).await;
14
15    let item = toasty::create!(Item {
16        id: 1_u8,
17        val: "hello"
18    })
19    .exec(&mut db)
20    .await?;
21    assert_struct!(item, _ { id: 1_u8, val: "hello" });
22
23    let read = Item::get_by_id(&mut db, &1_u8).await?;
24    assert_struct!(read, _ { id: 1_u8, val: "hello" });
25
26    item.delete().exec(&mut db).await?;
27    Ok(())
28}
29
30/// u16 as a manually-assigned primary key.
31#[driver_test]
32pub async fn key_u16(t: &mut Test) -> Result<()> {
33    #[derive(Debug, toasty::Model)]
34    struct Item {
35        #[key]
36        id: u16,
37        val: String,
38    }
39
40    let mut db = t.setup_db(models!(Item)).await;
41
42    let item = toasty::create!(Item {
43        id: 1_u16,
44        val: "hello"
45    })
46    .exec(&mut db)
47    .await?;
48    assert_struct!(item, _ { id: 1_u16, val: "hello" });
49
50    let read = Item::get_by_id(&mut db, &1_u16).await?;
51    assert_struct!(read, _ { id: 1_u16, val: "hello" });
52
53    item.delete().exec(&mut db).await?;
54    Ok(())
55}
56
57/// u32 as a manually-assigned primary key.
58#[driver_test]
59pub async fn key_u32(t: &mut Test) -> Result<()> {
60    #[derive(Debug, toasty::Model)]
61    struct Item {
62        #[key]
63        id: u32,
64        val: String,
65    }
66
67    let mut db = t.setup_db(models!(Item)).await;
68
69    let item = toasty::create!(Item {
70        id: 1_u32,
71        val: "hello"
72    })
73    .exec(&mut db)
74    .await?;
75    assert_struct!(item, _ { id: 1_u32, val: "hello" });
76
77    let read = Item::get_by_id(&mut db, &1_u32).await?;
78    assert_struct!(read, _ { id: 1_u32, val: "hello" });
79
80    item.delete().exec(&mut db).await?;
81    Ok(())
82}
83
84/// u64 as a manually-assigned primary key.
85#[driver_test]
86pub async fn key_u64(t: &mut Test) -> Result<()> {
87    #[derive(Debug, toasty::Model)]
88    struct Item {
89        #[key]
90        id: u64,
91        val: String,
92    }
93
94    let mut db = t.setup_db(models!(Item)).await;
95
96    let item = toasty::create!(Item {
97        id: 42_u64,
98        val: "hello"
99    })
100    .exec(&mut db)
101    .await?;
102    assert_struct!(item, _ { id: 42_u64, val: "hello" });
103
104    let read = Item::get_by_id(&mut db, &42_u64).await?;
105    assert_struct!(read, _ { id: 42_u64, val: "hello" });
106
107    item.delete().exec(&mut db).await?;
108    Ok(())
109}