pub struct IndexMetadata {
pub index_id: u32,
pub name: String,
pub catalog_name: String,
pub namespace_name: String,
pub table: String,
pub columns: Vec<String>,
pub column_indices: Vec<usize>,
pub unique: bool,
pub method: Option<IndexMethod>,
pub options: Vec<(String, String)>,
}Expand description
Metadata for an index in the catalog.
Contains the index ID, name, target table, columns, uniqueness flag, index method, and optional parameters.
§Examples
use alopex_sql::catalog::IndexMetadata;
use alopex_sql::ast::ddl::IndexMethod;
// Create a B-tree index on a single column
let btree_idx = IndexMetadata::new(1, "idx_users_name", "users", vec!["name".into()])
.with_column_indices(vec![1])
.with_method(IndexMethod::BTree);
assert_eq!(btree_idx.index_id, 1);
assert_eq!(btree_idx.name, "idx_users_name");
assert_eq!(btree_idx.table, "users");
assert_eq!(btree_idx.columns, vec!["name"]);
assert!(!btree_idx.unique);
// Create a unique composite index
let unique_idx = IndexMetadata::new(2, "idx_orders_composite", "orders", vec!["user_id".into(), "order_date".into()])
.with_column_indices(vec![0, 2])
.with_unique(true);
assert!(unique_idx.unique);
assert_eq!(unique_idx.columns.len(), 2);Fields§
§index_id: u32Unique index ID assigned by the catalog.
name: StringIndex name.
catalog_name: StringCatalog name.
namespace_name: StringNamespace name.
table: StringTarget table name.
columns: Vec<String>Target column names (supports composite indexes).
column_indices: Vec<usize>Column indices within the table (for IndexStorage).
unique: boolWhether this is a UNIQUE index.
method: Option<IndexMethod>Index method (BTree, Hnsw, etc.).
options: Vec<(String, String)>Index options (e.g., HNSW parameters: m, ef_construction).
Implementations§
Source§impl IndexMetadata
impl IndexMetadata
Sourcepub fn new(
index_id: u32,
name: impl Into<String>,
table: impl Into<String>,
columns: Vec<String>,
) -> Self
pub fn new( index_id: u32, name: impl Into<String>, table: impl Into<String>, columns: Vec<String>, ) -> Self
Create a new index metadata with the given ID, name, table, and columns.
The index defaults to non-unique, with no method specified, empty column_indices, and no options.
§Note
column_indices should be set via with_column_indices() after creation,
typically resolved by the Executor when the table schema is available.
Sourcepub fn with_column_indices(self, indices: Vec<usize>) -> Self
pub fn with_column_indices(self, indices: Vec<usize>) -> Self
Set the column indices (positions within the table).
Sourcepub fn with_unique(self, unique: bool) -> Self
pub fn with_unique(self, unique: bool) -> Self
Set whether this is a UNIQUE index.
Sourcepub fn with_method(self, method: IndexMethod) -> Self
pub fn with_method(self, method: IndexMethod) -> Self
Set the index method.
Sourcepub fn with_option(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_option( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add an index option.
Sourcepub fn with_options(self, options: Vec<(String, String)>) -> Self
pub fn with_options(self, options: Vec<(String, String)>) -> Self
Set multiple options at once.
Sourcepub fn get_option(&self, key: &str) -> Option<&str>
pub fn get_option(&self, key: &str) -> Option<&str>
Get an option value by key.
Returns None if the option doesn’t exist.
Sourcepub fn covers_column(&self, column: &str) -> bool
pub fn covers_column(&self, column: &str) -> bool
Check if this index covers the given column name.
Sourcepub fn is_single_column(&self) -> bool
pub fn is_single_column(&self) -> bool
Check if this is a single-column index.
Sourcepub fn first_column(&self) -> Option<&str>
pub fn first_column(&self) -> Option<&str>
Get the first (or only) column name.
Returns None if no columns are defined.
Trait Implementations§
Source§impl Clone for IndexMetadata
impl Clone for IndexMetadata
Source§fn clone(&self) -> IndexMetadata
fn clone(&self) -> IndexMetadata
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more