Skip to main content

icydb_schema/node/
primary_key.rs

1use crate::prelude::*;
2
3///
4/// PrimaryKey
5///
6/// Structured primary-key metadata for an entity schema.
7///
8
9#[derive(Clone, Debug, Serialize)]
10pub struct PrimaryKey {
11    field: &'static str,
12
13    #[serde(default)]
14    source: PrimaryKeySource,
15}
16
17impl PrimaryKey {
18    /// Build one primary-key declaration from field name and source.
19    #[must_use]
20    pub const fn new(field: &'static str, source: PrimaryKeySource) -> Self {
21        Self { field, source }
22    }
23
24    /// Borrow the primary-key field name.
25    #[must_use]
26    pub const fn field(&self) -> &'static str {
27        self.field
28    }
29
30    /// Borrow the primary-key source declaration.
31    #[must_use]
32    pub const fn source(&self) -> PrimaryKeySource {
33        self.source
34    }
35}
36
37///
38/// PrimaryKeySource
39///
40/// Declares where primary-key values originate.
41///
42
43#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize)]
44pub enum PrimaryKeySource {
45    #[default]
46    Internal,
47
48    External,
49}