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
//! # Kivis Derive Macros
//!
//! Procedural macros for the Kivis database schema library.
//! This crate provides the `Record` derive macro for automatically generating database schema types.
use TokenStream;
use ;
use crateGenerator;
use crateSchema;
/// Derive macro for generating database record implementations.
///
/// This macro generates the necessary traits and types for a struct to be used as a database record in Kivis.
/// It creates key types, index types, and implements the required traits for database operations.
///
/// # Attributes
///
/// - `#[key]`: Marks fields as part of the primary key
/// - `#[index]`: Marks fields for secondary indexing
/// - `#[derived_key(Type1, Type2, ...)]`: Specifies types for a derived key (mutually exclusive with `#[key]`)
///
/// # Key Strategies
///
/// The Record derive macro supports three key strategies:
///
/// 1. **Autoincrement keys**: No `#[key]` fields or `#[derived_key]` attribute (default u64 autoincrement)
/// 2. **Field keys**: Fields marked with `#[key]` attribute (derived from struct fields)
/// 3. **Derived keys**: Struct with `#[derived_key(...)]` attribute (requires manual `DeriveKey` implementation)
///
/// # Examples
///
/// ## Autoincrement Key
/// ```
/// use serde::{Serialize, Deserialize};
///
/// // This shows the basic structure - the actual Record derive would be used in practice
/// #[derive(Serialize, Deserialize, Debug, Clone)]
/// struct AutoIncrement {
/// name: String,
/// email: String,
/// }
/// ```
///
/// ## Field Key
/// ```
/// use serde::{Serialize, Deserialize};
///
/// // This shows the basic structure with key field - the actual Record derive would be used in practice
/// #[derive(Serialize, Deserialize, Debug)]
/// struct User {
/// id: u64, // Would be marked with #[key] in actual usage
/// name: String, // Would be marked with #[index] in actual usage
/// email: String,
/// }
/// ```
///
/// For complete working examples, see the tests in the `tests/` directory.