-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathselectable.rs
88 lines (75 loc) · 1.98 KB
/
selectable.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use diesel::*;
use helpers::connection;
table! {
my_structs (foo) {
foo -> Integer,
bar -> Integer,
}
}
#[test]
fn named_struct_definition() {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Queryable, Selectable)]
#[diesel(table_name = my_structs)]
struct MyStruct {
foo: i32,
bar: i32,
}
let conn = &mut connection();
let data = my_structs::table
.select(MyStruct::as_select())
.get_result(conn);
assert!(data.is_err());
}
#[test]
fn tuple_struct() {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Queryable, Selectable)]
#[diesel(table_name = my_structs)]
struct MyStruct(
#[diesel(column_name = foo)] i32,
#[diesel(column_name = bar)] i32,
);
let conn = &mut connection();
let data = my_structs::table
.select(MyStruct::as_select())
.get_result(conn);
assert!(data.is_err());
}
// FIXME: Test usage with renamed columns
#[test]
fn embedded_struct() {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Queryable, Selectable)]
#[diesel(table_name = my_structs)]
struct A<B> {
foo: i32,
#[diesel(embed)]
b: B,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Queryable, Selectable)]
#[diesel(table_name = my_structs)]
struct C {
bar: i32,
}
let conn = &mut connection();
let data = my_structs::table
.select(A::<C>::as_select())
.get_result(conn);
assert!(data.is_err());
}
#[test]
fn embedded_option() {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Queryable, Selectable)]
#[diesel(table_name = my_structs)]
struct A {
foo: i32,
#[diesel(embed)]
b: Option<B>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Queryable, Selectable)]
#[diesel(table_name = my_structs)]
struct B {
bar: i32,
}
let conn = &mut connection();
let data = my_structs::table.select(A::as_select()).get_result(conn);
assert!(data.is_err());
}