Skip to main content

Catalog

Struct Catalog 

Source
pub struct Catalog { /* private fields */ }
Expand description

A concrete, eager schema registry. Build it with Catalog::new and Catalog::table (or collect an iterator of CatalogTable), then hand Some(&catalog) to an extractor.

Internally a flat list of CatalogTables — the resolver scans it with right-anchored, cased matching, so there is no name-keyed index (a bare users may match several *.users entries, which is not a hashable equivalence). The optional default catalog / schema fill a bare or partially-qualified query reference before matching (like a single-entry search path); when unset, matching stays best-effort right-anchored.

Implementations§

Source§

impl Catalog

Source

pub fn new() -> Self

An empty catalog.

Source

pub fn table(self, table: CatalogTable) -> Self

Add one registered table. Returns self for chaining.

Source

pub fn default_catalog(self, catalog: impl Into<String>) -> Self

Set the default catalog used to fill a query reference that omits its catalog segment before matching. Returns self.

Source

pub fn default_schema(self, schema: impl Into<String>) -> Self

Set the default schema used to fill a bare query reference before matching. Returns self.

Source

pub fn from_ddl(dialect: &dyn Dialect, ddl: &str) -> Result<Self, Error>

Build a catalog from SQL DDL: every CREATE TABLE with an explicit column list becomes a registered table — its [catalog.]schema.name path and column names. Column types and constraints are ignored (only names are needed), so dialect-specific type syntax doesn’t matter as long as the statement parses. ddl is parsed with dialect, so pass the dialect matching your schema dump.

An unqualified CREATE TABLE t registers schema-less (no schema is fabricated); right-anchored matching still lets a bare query t — or even a qualified s.t — resolve to it. Skipped (not registered): statements that aren’t CREATE TABLE, CREATE TABLEs with no column definitions (... AS SELECT, ... LIKE ...), and names with more than three catalog.schema.name segments. A parse failure (the DDL is invalid for dialect) returns Err.

Only CREATE TABLE is interpreted. Session-default statements (USE ..., SET search_path ...) are not read — query-side defaults are the caller’s responsibility via Catalog::default_schema / Catalog::default_catalog.

use sql_insight::catalog::Catalog;
use sql_insight::sqlparser::dialect::GenericDialect;

let ddl = "CREATE TABLE users (id INT, name TEXT); \
           CREATE TABLE app.orders (id INT, total NUMERIC);";
let catalog = Catalog::from_ddl(&GenericDialect {}, ddl).unwrap();
// `users` registered schema-less; `app.orders` keeps its schema.
Source

pub fn from_ddl_with_casing( dialect: &dyn Dialect, ddl: &str, casing: IdentifierCasing, ) -> Result<Self, Error>

Like from_ddl but normalizes the stored identifiers with an explicit casing instead of the dialect default. Pass the same IdentifierCasing you give the extractor via ExtractorOptions::with_casing, so the catalog’s canonical form matches what a query reference folds to: from_ddl (dialect default) only matches when the extraction also uses the default, so a case-sensitive override needs this to resolve.

Trait Implementations§

Source§

impl Clone for Catalog

Source§

fn clone(&self) -> Catalog

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Catalog

Source§

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

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

impl Default for Catalog

Source§

fn default() -> Catalog

Returns the “default value” for a type. Read more
Source§

impl Eq for Catalog

Source§

impl FromIterator<CatalogTable> for Catalog

Source§

fn from_iter<I: IntoIterator<Item = CatalogTable>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for Catalog

Source§

fn eq(&self, other: &Catalog) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Catalog

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, 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.