Skip to main content

toasty_driver_integration_suite/tests/
select_projection_wide.rs

1//! `.select(...)` with a wide tuple projection. Tuple `Load` and `IntoExpr`
2//! impls are generated up to 16 elements; this file pins the upper bound so
3//! a regression back to a smaller arity fails to compile here.
4
5use crate::prelude::*;
6
7#[derive(Debug, toasty::Model)]
8struct Wide {
9    #[key]
10    id: i64,
11    f1: String,
12    f2: String,
13    f3: String,
14    f4: String,
15    f5: String,
16    f6: String,
17    f7: String,
18    f8: String,
19    f9: String,
20    f10: String,
21    f11: String,
22    f12: String,
23    f13: String,
24    f14: String,
25    f15: String,
26}
27
28/// Selecting sixteen fields as a single tuple loads every column in order.
29#[driver_test]
30pub async fn select_sixteen_field_tuple(test: &mut Test) -> Result<()> {
31    let mut db = test.setup_db(models!(Wide)).await;
32
33    Wide::create()
34        .id(1_i64)
35        .f1("v1")
36        .f2("v2")
37        .f3("v3")
38        .f4("v4")
39        .f5("v5")
40        .f6("v6")
41        .f7("v7")
42        .f8("v8")
43        .f9("v9")
44        .f10("v10")
45        .f11("v11")
46        .f12("v12")
47        .f13("v13")
48        .f14("v14")
49        .f15("v15")
50        .exec(&mut db)
51        .await?;
52
53    let f = Wide::fields();
54    #[allow(clippy::type_complexity)]
55    let rows: Vec<(
56        i64,
57        String,
58        String,
59        String,
60        String,
61        String,
62        String,
63        String,
64        String,
65        String,
66        String,
67        String,
68        String,
69        String,
70        String,
71        String,
72    )> = Wide::all()
73        .select((
74            f.id(),
75            f.f1(),
76            f.f2(),
77            f.f3(),
78            f.f4(),
79            f.f5(),
80            f.f6(),
81            f.f7(),
82            f.f8(),
83            f.f9(),
84            f.f10(),
85            f.f11(),
86            f.f12(),
87            f.f13(),
88            f.f14(),
89            f.f15(),
90        ))
91        .exec(&mut db)
92        .await?;
93
94    // `PartialEq` and `Debug` for std tuples stop at 12 elements, so
95    // destructure rather than compare the whole tuple.
96    assert_eq!(rows.len(), 1);
97    let (id, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15) =
98        rows.into_iter().next().unwrap();
99    assert_eq!(id, 1_i64);
100    assert_eq!(
101        [
102            f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15
103        ],
104        [
105            "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13",
106            "v14", "v15"
107        ]
108    );
109
110    Ok(())
111}