pub struct TableMetadata {
pub table_id: u32,
pub name: String,
pub columns: Vec<ColumnMetadata>,
pub primary_key: Option<Vec<String>>,
pub storage_options: StorageOptions,
}Expand description
Metadata for a table in the catalog.
Contains the table ID, name, column definitions, and optional primary key constraint.
§Examples
use alopex_sql::catalog::{TableMetadata, ColumnMetadata};
use alopex_sql::planner::types::ResolvedType;
let columns = vec![
ColumnMetadata::new("id", ResolvedType::Integer)
.with_primary_key(true)
.with_not_null(true),
ColumnMetadata::new("name", ResolvedType::Text)
.with_not_null(true),
];
let table = TableMetadata::new("users", columns)
.with_primary_key(vec!["id".to_string()]);
assert_eq!(table.name, "users");
assert!(table.get_column("id").is_some());
assert_eq!(table.column_names(), vec!["id", "name"]);Fields§
§table_id: u32Unique table ID assigned by the catalog.
name: StringTable name.
columns: Vec<ColumnMetadata>Column definitions (order is preserved).
primary_key: Option<Vec<String>>Primary key columns (supports composite keys).
storage_options: StorageOptionsStorage configuration (row/columnar, compression, row group sizing).
Implementations§
Source§impl TableMetadata
impl TableMetadata
Sourcepub fn new(name: impl Into<String>, columns: Vec<ColumnMetadata>) -> Self
pub fn new(name: impl Into<String>, columns: Vec<ColumnMetadata>) -> Self
Create a new table metadata with the given name and columns.
The table_id defaults to 0; use with_table_id() to set it,
or it will be assigned by the Catalog when the table is created.
Sourcepub fn with_table_id(self, table_id: u32) -> Self
pub fn with_table_id(self, table_id: u32) -> Self
Set the table ID.
Sourcepub fn with_primary_key(self, columns: Vec<String>) -> Self
pub fn with_primary_key(self, columns: Vec<String>) -> Self
Set the primary key columns.
Sourcepub fn get_column(&self, name: &str) -> Option<&ColumnMetadata>
pub fn get_column(&self, name: &str) -> Option<&ColumnMetadata>
Get a column by name.
Returns None if the column doesn’t exist.
§Examples
use alopex_sql::catalog::{TableMetadata, ColumnMetadata};
use alopex_sql::planner::types::ResolvedType;
let table = TableMetadata::new("users", vec![
ColumnMetadata::new("id", ResolvedType::Integer),
ColumnMetadata::new("name", ResolvedType::Text),
]);
assert!(table.get_column("id").is_some());
assert!(table.get_column("unknown").is_none());Sourcepub fn get_column_index(&self, name: &str) -> Option<usize>
pub fn get_column_index(&self, name: &str) -> Option<usize>
Get the index of a column by name.
Returns None if the column doesn’t exist.
Sourcepub fn column_names(&self) -> Vec<&str>
pub fn column_names(&self) -> Vec<&str>
Get a list of all column names in definition order.
§Examples
use alopex_sql::catalog::{TableMetadata, ColumnMetadata};
use alopex_sql::planner::types::ResolvedType;
let table = TableMetadata::new("users", vec![
ColumnMetadata::new("id", ResolvedType::Integer),
ColumnMetadata::new("name", ResolvedType::Text),
ColumnMetadata::new("age", ResolvedType::Integer),
]);
assert_eq!(table.column_names(), vec!["id", "name", "age"]);Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Get the number of columns in the table.
Trait Implementations§
Source§impl Clone for TableMetadata
impl Clone for TableMetadata
Source§fn clone(&self) -> TableMetadata
fn clone(&self) -> TableMetadata
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TableMetadata
impl Debug for TableMetadata
Source§impl From<&TableMetadata> for PersistedTableMeta
impl From<&TableMetadata> for PersistedTableMeta
Source§fn from(value: &TableMetadata) -> Self
fn from(value: &TableMetadata) -> Self
Source§impl From<PersistedTableMeta> for TableMetadata
impl From<PersistedTableMeta> for TableMetadata
Source§fn from(value: PersistedTableMeta) -> Self
fn from(value: PersistedTableMeta) -> Self
Auto Trait Implementations§
impl Freeze for TableMetadata
impl RefUnwindSafe for TableMetadata
impl Send for TableMetadata
impl Sync for TableMetadata
impl Unpin for TableMetadata
impl UnwindSafe for TableMetadata
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)