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    source: PrimaryKeySource,
13}
14
15impl PrimaryKey {
16    /// Build one primary-key declaration from field name and source.
17    #[must_use]
18    pub const fn new(field: &'static str, source: PrimaryKeySource) -> Self {
19        Self { field, source }
20    }
21
22    /// Borrow the primary-key field name.
23    #[must_use]
24    pub const fn field(&self) -> &'static str {
25        self.field
26    }
27
28    /// Borrow the primary-key source declaration.
29    #[must_use]
30    pub const fn source(&self) -> PrimaryKeySource {
31        self.source
32    }
33}
34
35///
36/// PrimaryKeySource
37///
38/// Declares where primary-key values originate.
39///
40
41#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize)]
42pub enum PrimaryKeySource {
43    #[default]
44    Internal,
45
46    External,
47}