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
//! Procedural macros for Rust Entity Framework (rust-ef).
use TokenStream;
/// Derive a typed keyed-`DbContext` key.
///
/// The enum's variants become `IDbContextKey::name()` values (snake-case by
/// default, overridable with `#[key("...")]`) and the type implements
/// `From<Key> for rust_dix::ServiceKey`. This makes
/// `#[inject(owned, key = Key::Read)]` and `add_dbcontext_keyed(Key::Read, ...)`
/// share the same typed key.
///
/// ```ignore
/// #[derive(DbContextKey, Debug, Clone, Copy, PartialEq, Eq, Hash)]
/// enum Db {
/// Read,
/// Write,
/// #[key("audit-log")]
/// Audit,
/// }
/// ```
///
/// The enum must derive `Debug + Clone + Copy + PartialEq + Eq + Hash` (the
/// bounds required by `rust_dix::ServiceKey::new`).
/// Derive string-backed database mapping for a unit-only enum.
///
/// Generates `From<Enum> for DbValue`, `TryFrom<DbValue> for Enum`,
/// `as_str()` and `from_db_str()`. Variant names default to the Rust variant
/// identifier; override with `#[db_value("...")]`.
///
/// ```ignore
/// #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, DbEnum)]
/// enum Status {
/// #[default]
/// Pending,
/// #[db_value("PAID")]
/// Paid,
/// }
/// ```
/// Compile-time LINQ-to-SQL.
///
/// ```ignore
/// linq!(ctx.set::<Blog>(), |b: Blog| b.rating > 5).to_list().await?;
///
/// let expr = linq!(|b: Blog| b.rating > min);
/// ctx.set::<Blog>().filter(expr).to_list().await?;
/// ```
/// Attribute macro for `impl IEntityTypeConfiguration<T>` blocks.
///
/// Emits an `inventory::submit!` registering the configuration for automatic
/// discovery by `DbContext::from_options()`. The first argument is the entity
/// type `T`; the config type is taken from the `impl`'s `Self` type. An
/// optional second argument specifies the DbContext key for multi-database
/// scenarios.
///
/// # Examples
///
/// ```ignore
/// #[derive(Default)]
/// pub struct BlogConfig;
///
/// // Default context
/// #[entity(Blog)]
/// impl IEntityTypeConfiguration<Blog> for BlogConfig {
/// fn configure(&self, entity: &mut EntityTypeBuilder<'_, Blog>) {
/// entity.to_table("blogs_renamed");
/// }
/// }
///
/// // Keyed context ("logs" database)
/// #[entity(LogEntry, "logs")]
/// impl LogEntryConfig for IEntityTypeConfiguration<LogEntry> {
/// fn configure(&self, entity: &mut EntityTypeBuilder<'_, LogEntry>) {
/// entity.to_table("app_logs");
/// }
/// }
/// ```