Skip to main content

TableReference

Struct TableReference 

Source
pub struct TableReference {
    pub catalog: Option<Ident>,
    pub schema: Option<Ident>,
    pub name: Ident,
}
Expand description

Physical table identity — the catalog.schema.name triplet.

TableReference deliberately carries no alias: aliasing is a use-site decoration, not part of a table’s identity. Use-site alias information, when needed, is carried by the structures that wrap a TableReference (e.g. resolver bindings).

Equality has two levels. The derived Eq / Hash are structural — case- and quote-sensitive, exact segments. That is the right dedup when references come from catalog-backed analysis (matched tables are canonicalized, so equal tables produce equal references) and for direct cross-statement comparison. For catalog-free dedup, where the same table may appear under fold-equivalent spellings (users vs USERS), use identity_key / same_table, which fold by a dialect’s IdentifierCasing.

Fields§

§catalog: Option<Ident>§schema: Option<Ident>§name: Ident

Implementations§

Source§

impl TableReference

Source

pub fn identity_key(&self, casing: &IdentifierCasing) -> TableIdentityKey

The dialect-aware TableIdentityKey for this reference: each segment folded by casing’s table rule. Equal keys denote the same table under that dialect’s casing.

This is the catalog-free dedup key. The structural Eq on TableReference is exact (case- and quote-sensitive), so without a catalog to canonicalize spellings it over-counts users and USERS as two tables; folding by the dialect’s casing collapses them.

use std::collections::HashSet;
use sql_insight::{CaseRule, IdentifierCasing, TableReference};

let users = TableReference { catalog: None, schema: None, name: "users".into() };
let upper = TableReference { catalog: None, schema: None, name: "USERS".into() };

// Structural equality is exact — these read as two different tables.
assert_ne!(users, upper);

// Under a case-folding dialect (here lower-folding, e.g. PostgreSQL)
// they share one identity.
let casing = IdentifierCasing::uniform(CaseRule::Lower);
assert!(users.same_table(&upper, &casing));

// So a fold-keyed set counts the table once, where a structural
// `HashSet<TableReference>` would count two.
let distinct: HashSet<_> = [&users, &upper]
    .iter()
    .map(|t| t.identity_key(&casing))
    .collect();
assert_eq!(distinct.len(), 1);

// Identity, not wildcard: a bare name and a schema-qualified one stay
// distinct (different identities, not a prefix match).
let qualified = TableReference {
    catalog: None,
    schema: Some("public".into()),
    name: "users".into(),
};
assert!(!users.same_table(&qualified, &casing));
Source

pub fn same_table(&self, other: &Self, casing: &IdentifierCasing) -> bool

Whether self and other denote the same table under casing — equivalent to comparing their identity_keys.

Trait Implementations§

Source§

impl Clone for TableReference

Source§

fn clone(&self) -> TableReference

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 TableReference

Source§

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

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

impl Display for TableReference

Source§

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

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

impl Eq for TableReference

Source§

impl Hash for TableReference

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TableReference

Source§

fn eq(&self, other: &TableReference) -> 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 TableReference

Source§

impl TryFrom<&Insert> for TableReference

Source§

type Error = Error

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

fn try_from(value: &Insert) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&ObjectName> for TableReference

Source§

type Error = Error

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

fn try_from(obj_name: &ObjectName) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&TableFactor> for TableReference

Source§

type Error = Error

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

fn try_from(table: &TableFactor) -> Result<Self, Self::Error>

Performs the conversion.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.