From 215485d403d6aed0937265844b18d5415824bb5e Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Thu, 21 Aug 2025 11:00:51 +0300 Subject: [PATCH] Add Table::get_column_by_name method --- core/schema.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/schema.rs b/core/schema.rs index c5b0cfb7e..ac1573909 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -603,6 +603,24 @@ impl Table { } } + /// Returns the column position and column for a given column name. + pub fn get_column_by_name(&self, name: &str) -> Option<(usize, &Column)> { + let name = normalize_ident(name); + match self { + Self::BTree(table) => table.get_column(name.as_str()), + Self::Virtual(table) => table + .columns + .iter() + .enumerate() + .find(|(_, col)| col.name.as_ref() == Some(&name)), + Self::FromClauseSubquery(from_clause_subquery) => from_clause_subquery + .columns + .iter() + .enumerate() + .find(|(_, col)| col.name.as_ref() == Some(&name)), + } + } + pub fn columns(&self) -> &Vec { match self { Self::BTree(table) => &table.columns,