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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use ;
use crate;
/// An index defined on a model's fields.
///
/// Indices speed up queries by letting the database locate rows without a full
/// table scan. An index can cover one or more fields, may enforce uniqueness,
/// and may serve as the primary key.
///
/// Fields are split into *partition* fields (used for distribution in NoSQL
/// backends like DynamoDB) and *local* fields (sort keys or secondary columns).
///
/// # Examples
///
/// ```
/// use toasty_core::schema::app::{Index, IndexId, IndexField, ModelId};
/// use toasty_core::schema::db::{IndexOp, IndexScope};
///
/// let index = Index {
/// id: IndexId { model: ModelId(0), index: 0 },
/// fields: vec![IndexField {
/// field: ModelId(0).field(0),
/// op: IndexOp::Eq,
/// scope: IndexScope::Local,
/// }],
/// unique: true,
/// primary_key: true,
/// };
/// assert!(index.unique);
/// assert!(index.primary_key);
/// ```
/// Uniquely identifies an [`Index`] within a schema.
///
/// Composed of the owning model's [`ModelId`] and a positional index into that
/// model's index list.
///
/// # Examples
///
/// ```
/// use toasty_core::schema::app::{IndexId, ModelId};
///
/// let id = IndexId { model: ModelId(0), index: 0 };
/// assert_eq!(id.model, ModelId(0));
/// ```
/// A single field entry within an [`Index`].
///
/// Describes which field is indexed, the comparison operation used for lookups,
/// and whether this field is a partition key or a local (sort) key.
///
/// # Examples
///
/// ```
/// use toasty_core::schema::app::{IndexField, ModelId};
/// use toasty_core::schema::db::{IndexOp, IndexScope};
///
/// let field = IndexField {
/// field: ModelId(0).field(1),
/// op: IndexOp::Eq,
/// scope: IndexScope::Local,
/// };
/// ```