IndexMetadata

Struct IndexMetadata 

Source
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: u32

Unique index ID assigned by the catalog.

§name: String

Index name.

§catalog_name: String

Catalog name.

§namespace_name: String

Namespace name.

§table: String

Target table name.

§columns: Vec<String>

Target column names (supports composite indexes).

§column_indices: Vec<usize>

Column indices within the table (for IndexStorage).

§unique: bool

Whether 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

Source

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.

Source

pub fn with_column_indices(self, indices: Vec<usize>) -> Self

Set the column indices (positions within the table).

Source

pub fn with_unique(self, unique: bool) -> Self

Set whether this is a UNIQUE index.

Source

pub fn with_method(self, method: IndexMethod) -> Self

Set the index method.

Source

pub fn with_option( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Add an index option.

Source

pub fn with_options(self, options: Vec<(String, String)>) -> Self

Set multiple options at once.

Source

pub fn get_option(&self, key: &str) -> Option<&str>

Get an option value by key.

Returns None if the option doesn’t exist.

Source

pub fn covers_column(&self, column: &str) -> bool

Check if this index covers the given column name.

Source

pub fn is_single_column(&self) -> bool

Check if this is a single-column index.

Source

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

Source§

fn clone(&self) -> IndexMetadata

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IndexMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&IndexMetadata> for IndexFqn

Source§

fn from(value: &IndexMetadata) -> Self

Converts to this type from the input type.
Source§

impl From<&IndexMetadata> for PersistedIndexMeta

Source§

fn from(value: &IndexMetadata) -> Self

Converts to this type from the input type.
Source§

impl From<PersistedIndexMeta> for IndexMetadata

Source§

fn from(value: PersistedIndexMeta) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,