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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//! Compile-time metadata for secondary indexes declared via the
//! `#[derive(SecondaryKey)]` proc-macro.
//!
//! When a user writes
//!
//! ```ignore
//! #[derive(noxu_persist::Entity, noxu_persist::SecondaryKey)]
//! struct User {
//! #[primary_key]
//! id: u64,
//! #[secondary_key(name = "by_email", relate = OneToOne)]
//! email: String,
//! #[secondary_key(
//! name = "by_dept",
//! relate = ManyToOne,
//! related_entity = "Department",
//! on_related_entity_delete = NULLIFY,
//! )]
//! dept: Option<u64>,
//! }
//! ```
//!
//! the derive emits a `pub const SECONDARY_INDEXES: &'static [SecondarySpec]`
//! describing every declared index, plus a typed
//! `open_<name>_index(primary)` helper per field. The const-table is the
//! Rust analogue of the JE `PersistKeyMetadata` reflective view.
//!
//! `SecondarySpec` is *only* metadata: it does not own an extractor closure
//! and is therefore `Copy + 'static`. The actual `SecondaryIndex`
//! registration is performed by the per-field helper methods that the
//! derive emits, because the secondary-key type `SK` is field-specific and
//! cannot be erased into a const table.
/// Cardinality of a secondary index relationship.
///
/// Mirrors the `Relationship` enum from BDB-JE
/// (`com.sleepycat.persist.model.Relationship`):
///
/// | JE constant | Noxu variant | Meaning |
/// |---|---|---|
/// | `ONE_TO_ONE` | `OneToOne` | each entity has exactly one secondary key, and the secondary key is unique across all entities |
/// | `MANY_TO_ONE` | `ManyToOne` | each entity has exactly one secondary key, but multiple entities may share the same secondary key (the common case) |
/// | `ONE_TO_MANY` | `OneToMany` | each entity has multiple secondary keys; each secondary key is unique |
/// | `MANY_TO_MANY` | `ManyToMany` | each entity has multiple secondary keys, multiple entities may share keys |
///
/// noxu-persist's `SecondaryIndex` extractor signature is
/// `Fn(&E) -> Option<SK>` — one secondary key per entity — so only
/// `OneToOne` and `ManyToOne` are fully exercised by the engine.
/// `OneToMany` / `ManyToMany` are accepted by the derive (so the metadata
/// round-trips cleanly) but the extractor still returns a single key; users
/// that need multi-key extraction should register multiple secondary
/// indexes manually until a multi-key extractor lands.
/// Action taken when an entity referenced by a foreign-key secondary index
/// is deleted from its primary `EntityStore`.
///
/// Mirrors `com.sleepycat.persist.model.DeleteAction` from BDB-JE.
///
/// DPL secondary indexes are persistent, transactional
/// `noxu-db` `SecondaryDatabase`s, but the DPL `open_secondary_index`
/// path does not yet wire this `on_related_entity_delete` attribute into
/// the lower-level `noxu-db` foreign-key cascade machinery — the field is
/// **metadata only**, recorded in `SecondarySpec` so callers can inspect
/// the user's intent. (The `noxu-db` `SecondaryConfig` foreign-key
/// support exists and can be used directly when FK enforcement is
/// required; wiring the DPL attribute into it is a future item.)
/// Compile-time metadata describing a single secondary index declared on
/// an entity via `#[secondary_key(...)]`.
///
/// Fields mirror the BDB-JE `@SecondaryKey` annotation fields one-for-one:
///
/// | JE field | Noxu field | Required |
/// |---|---|---|
/// | `name` | `name` | yes |
/// | `relate` | `relate` | yes |
/// | `relatedEntity` | `related_entity` | no |
/// | `onRelatedEntityDelete` | `on_related_entity_delete` | no (default `Abort`) |
///
/// The derive emits one `SecondarySpec` per `#[secondary_key(...)]` field,
/// collected into a `pub const SECONDARY_INDEXES: &[SecondarySpec]` on the
/// entity struct. This is observable at runtime via
/// `Entity::secondary_specs()` (auto-implemented by the derive).