toasty_core/schema/db/pk.rs
1use super::{ColumnId, IndexId};
2
3/// The primary key definition for a database table.
4///
5/// Lists the columns that make up the primary key and references the
6/// corresponding [`Index`](super::Index).
7///
8/// # Examples
9///
10/// ```ignore
11/// use toasty_core::schema::db::{PrimaryKey, ColumnId, IndexId, TableId};
12///
13/// let pk = PrimaryKey {
14/// columns: vec![
15/// ColumnId { table: TableId(0), index: 0 },
16/// ],
17/// index: IndexId { table: TableId(0), index: 0 },
18/// };
19///
20/// assert_eq!(pk.columns.len(), 1);
21/// ```
22#[derive(Debug, Clone, PartialEq)]
23#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
24pub struct PrimaryKey {
25 /// Columns composing the primary key, in order.
26 pub columns: Vec<ColumnId>,
27
28 /// The index backing this primary key.
29 pub index: IndexId,
30}