rjango_contrib_postgres/
indexes.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4pub struct BTreeIndex {
5 pub fields: Vec<String>,
6}
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9pub struct BrinIndex {
10 pub fields: Vec<String>,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14pub struct GinIndex {
15 pub fields: Vec<String>,
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
19pub struct GistIndex {
20 pub fields: Vec<String>,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
24pub struct HashIndex {
25 pub fields: Vec<String>,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
29pub struct SpGistIndex {
30 pub fields: Vec<String>,
31}
32
33#[cfg(test)]
34mod tests {
35 use super::{BTreeIndex, BrinIndex, GinIndex, GistIndex, HashIndex, SpGistIndex};
36
37 #[test]
38 fn btree_index_construction_preserves_fields() {
39 let index = BTreeIndex {
40 fields: vec!["slug".to_string()],
41 };
42
43 assert_eq!(index.fields, ["slug"]);
44 }
45
46 #[test]
47 fn brin_index_construction_preserves_fields() {
48 let index = BrinIndex {
49 fields: vec!["created_at".to_string()],
50 };
51
52 assert_eq!(index.fields, ["created_at"]);
53 }
54
55 #[test]
56 fn gin_index_construction_preserves_fields() {
57 let index = GinIndex {
58 fields: vec!["search_vector".to_string()],
59 };
60
61 assert_eq!(index.fields, ["search_vector"]);
62 }
63
64 #[test]
65 fn gist_index_construction_preserves_fields() {
66 let index = GistIndex {
67 fields: vec!["period".to_string()],
68 };
69
70 assert_eq!(index.fields, ["period"]);
71 }
72
73 #[test]
74 fn hash_index_construction_preserves_fields() {
75 let index = HashIndex {
76 fields: vec!["checksum".to_string()],
77 };
78
79 assert_eq!(index.fields, ["checksum"]);
80 }
81
82 #[test]
83 fn spgist_index_construction_preserves_fields() {
84 let index = SpGistIndex {
85 fields: vec!["point".to_string()],
86 };
87
88 assert_eq!(index.fields, ["point"]);
89 }
90}