reifydb_core/interface/catalog/
column.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use std::ops::Deref;
5
6use reifydb_type::TypeConstraint;
7use serde::{Deserialize, Serialize};
8
9use crate::{
10	interface::{ColumnId, ColumnPolicy},
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}
23
24#[repr(transparent)]
25#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash, Serialize, Deserialize)]
26pub struct ColumnIndex(pub u16);
27
28impl Deref for ColumnIndex {
29	type Target = u16;
30
31	fn deref(&self) -> &Self::Target {
32		&self.0
33	}
34}
35
36impl PartialEq<u16> for ColumnIndex {
37	fn eq(&self, other: &u16) -> bool {
38		self.0.eq(other)
39	}
40}
41
42impl From<ColumnIndex> for u16 {
43	fn from(value: ColumnIndex) -> Self {
44		value.0
45	}
46}
47
48impl From<&[ColumnDef]> for EncodedValuesNamedLayout {
49	fn from(value: &[ColumnDef]) -> Self {
50		EncodedValuesNamedLayout::new(value.iter().map(|col| (col.name.clone(), col.constraint.get_type())))
51	}
52}