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
use TokenStream;
/// The derive macro to add `agdb` compatibility
/// to user defined types. It implements [`agdb::UserDbType`]
/// for the type automatically to allow your type to be read and
/// stored from/to the database.
///
/// If your type contains a field `db_id: Option<agdb::DbId>`
/// it will be treated specially and will additionally allow
/// shorthand inserts/updates of the elements directly.
///
/// All database types are supported. User (custom) types must either
/// `impl From<T> for agdb::DbValue` and `impl TryFrom<agdb::DbValue> for T { type Error = agdb::DbError }`
/// or you must use `#[agdb(flatten)]` attribute to merge the fields in a flat list (transitively). Flattened
/// types must themselves be derived from `agdb::DbType` (or implement `agdb::UserDbType`)
///
/// NOTE: if the nested struct(s) have keys of the same name the value will
/// be overwritten by the last encountered field of the same name (transitively).
/// Use `#[agdb(rename = "new_name")]` to disambiguate.
///
/// `Option` can be used on on any supported type. If a value type is
/// an `Option` and runtime value is `None` the value will NOT be stored
/// in the database. When reading elements if a type contains
/// an `Option` all keys are always retrieved and searched for individual
/// keys.
///
/// # Examples
///
/// ## Standard
/// ```ignore
/// #[derive(DbType)]
/// struct MyValue {
/// num_value: i64,
/// string_value: String,
/// vec_value: Vec<u64>,
/// }
/// ```
///
/// ## With db_id
/// ```ignore
/// #[derive(DbType)]
/// struct MyValue {
/// db_id: Option<agdb::DbId>, //this field is useful but not mandatory
/// num_value: i64,
/// string_value: String,
/// vec_value: Vec<u64>,
/// }
/// ```
///
/// ## With optional
/// ```ignore
/// #[derive(DbType)]
/// struct MyValue {
/// db_id: Option<agdb::DbId>, //this field is useful but not mandatory
/// num_value: i64,
/// string_value: Option<String>, // Optional value will not be stored if None
/// vec_value: Vec<u64>,
/// }
/// ```
///
/// ## Flatten
/// ```ignore
/// #[derive(DbType)]
/// struct MyValue {
/// num_value: i64,
/// #[agdb(flatten)]
/// nested: NestedStruct,
/// }
/// ```
/// The same as DbType but additionally implements `DbType::db_element_id()` allowing
/// more streamlined selection and search of strongly typed elements. This derive adds
/// additional element property to the element representation in the database of type
/// `(String, String)`, i.e. `("db_element_id", <usertypename>.to_string())`.
/// The helper derive macro to add `agdb` compatibility to
/// user defined types. This type provides blank implementation
/// of the `agdb::DbTypeMarker` trait. This is needed for the
/// vectorized custom values to be compatible with the database
/// as the `From` trait implementation without it conflicts
/// with the blanket implementations.
///
/// # Examples
///
/// ```ignore
/// #[derive(agdb::DbTypeMarker, Default, Copy, Clone, Debug)]
/// enum MyEnum {
/// #[default]
/// A,
/// B,
/// }
/// ```
/// The derive macro to add `agdb` platform agnostic serialization
/// support. This is only needed if you want to serialize custom
/// complex data structures and do not want or cannot use serde.
/// It is primarily used internally to serialize the `agdb` data
/// structures.
/// The derive macro to allow automatically serializing user types
/// into `DbValue::Bytes`. Useful when deriving `DbType` for
/// a custom type with nested custom types or enums as it avoids
/// the need to manually implement From/TryFrom for such nested types.
/// It does additionally support enums and vectorized types (`Vec<T>`).
///
/// NOTE: It requires both `DbTypeMarker` and `AgdbSerialize` traits
/// to be implemented. You can derive them with `#[derive(DbTypeMarker, AgdbSerialize)]`.