reifydb_core/interface/catalog/
column.rs1use std::ops::Deref;
5
6use reifydb_type::TypeConstraint;
7use serde::{Deserialize, Serialize};
8
9use crate::{
10 interface::{ColumnId, ColumnPolicy, DictionaryId},
11 value::encoded::EncodedValuesNamedLayout,
12};
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15pub struct ColumnDef {
16 pub id: ColumnId,
17 pub name: String,
18 pub constraint: TypeConstraint,
19 pub policies: Vec<ColumnPolicy>,
20 pub index: ColumnIndex,
21 pub auto_increment: bool,
22 pub dictionary_id: Option<DictionaryId>,
23}
24
25#[repr(transparent)]
26#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash, Serialize, Deserialize)]
27pub struct ColumnIndex(pub u8);
28
29impl Deref for ColumnIndex {
30 type Target = u8;
31
32 fn deref(&self) -> &Self::Target {
33 &self.0
34 }
35}
36
37impl PartialEq<u8> for ColumnIndex {
38 fn eq(&self, other: &u8) -> bool {
39 self.0.eq(other)
40 }
41}
42
43impl From<ColumnIndex> for u8 {
44 fn from(value: ColumnIndex) -> Self {
45 value.0
46 }
47}
48
49impl From<&[ColumnDef]> for EncodedValuesNamedLayout {
50 fn from(value: &[ColumnDef]) -> Self {
51 EncodedValuesNamedLayout::new(value.iter().map(|col| (col.name.clone(), col.constraint.get_type())))
52 }
53}