TableIdentifier

Struct TableIdentifier 

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

A SQL identifier with proper case handling per SQL:1999.

This type separates three concerns:

  • Canonical form: Used for HashMap keys and equality comparison
  • Display form: Preserves user’s original input for error messages
  • Quoted flag: Whether the identifier was delimited (quoted)

§SQL:1999 Compliance

Per SQL:1999, identifier handling depends on whether the identifier was quoted:

InputQuotedCanonicalMatches mytable?Matches "MyTable"?
MyTableNomytableYesNo
"MyTable"YesMyTableNoYes
MYTABLENomytableYesNo
"mytable"YesmytableYes (same canonical)No

§Compound Identifiers

TableIdentifier supports schema-qualified table names where each component (schema and table) can be independently quoted or unquoted:

SQLSchema PartTable PartCanonical Form
myApp.usersunquotedunquotedmyapp.users
"myApp".usersquotedunquotedmyApp.users
myapp."Users"unquotedquotedmyapp.Users
"myApp"."Users"quotedquotedmyApp.Users

Implementations§

Source§

impl TableIdentifier

Source

pub fn new(name: &str, quoted: bool) -> Self

Create a new table identifier.

§Arguments
  • name - The identifier name as written by the user
  • quoted - Whether the identifier was quoted (delimited) in SQL
§SQL:1999 Behavior
  • If quoted is false: The canonical form is lowercase-folded for case-insensitive comparison.

  • If quoted is true: The canonical form preserves exact case for case-sensitive comparison. This matches SQL:1999 behavior for delimited identifiers.

§Example
use vibesql_ast::TableIdentifier;

// Unquoted: case-insensitive
let unquoted = TableIdentifier::new("MyTable", false);
assert_eq!(unquoted.canonical(), "mytable");
assert_eq!(unquoted.display(), "MyTable");

// Quoted: case-sensitive
let quoted = TableIdentifier::new("MyTable", true);
assert_eq!(quoted.canonical(), "MyTable");
assert_eq!(quoted.display(), "MyTable");
Source

pub fn from_canonical(canonical: String, quoted: bool) -> Self

Create an identifier from a canonical name (for internal use).

This is used when loading from persistence where we only have the canonical form. The display form is set to match canonical.

Source

pub fn qualified( schema_name: &str, schema_quoted: bool, table_name: &str, table_quoted: bool, ) -> Self

Create a qualified (schema.table) identifier.

Each component (schema and table) has independent quoted/unquoted semantics.

§Arguments
  • schema_name - The schema name as written by the user
  • schema_quoted - Whether the schema was quoted in SQL
  • table_name - The table name as written by the user
  • table_quoted - Whether the table was quoted in SQL
§SQL:1999 Behavior

Each identifier component is independent:

  • Unquoted: canonical form is lowercase (case-insensitive)
  • Quoted: canonical form preserves case (case-sensitive)
§Example
use vibesql_ast::TableIdentifier;

// "myApp".users → myApp.users (schema case-sensitive, table case-insensitive)
let id = TableIdentifier::qualified("myApp", true, "users", false);
assert_eq!(id.canonical(), "myApp.users");

// myapp."Users" → myapp.Users (schema case-insensitive, table case-sensitive)
let id = TableIdentifier::qualified("myapp", false, "Users", true);
assert_eq!(id.canonical(), "myapp.Users");
Source

pub fn canonical(&self) -> &str

Get the canonical form of the identifier.

This is used for HashMap keys and equality comparison.

  • Unquoted identifiers: lowercase
  • Quoted identifiers: exact case preserved
Source

pub fn display(&self) -> &str

Get the display form of the identifier.

This preserves the user’s original input and should be used in error messages and user-facing output.

Source

pub fn is_quoted(&self) -> bool

Check if this identifier was quoted (delimited) in the original SQL.

Source

pub fn into_canonical(self) -> String

Get the canonical form as an owned String.

Useful for HashMap operations that need owned keys.

Source

pub fn is_qualified(&self) -> bool

Check if this is a qualified (schema.table) identifier.

Source

pub fn schema_canonical(&self) -> Option<&str>

Get the schema part canonical form (if this is a qualified identifier).

Source

pub fn schema_display(&self) -> Option<&str>

Get the schema part display form (if this is a qualified identifier).

Source

pub fn is_schema_quoted(&self) -> bool

Check if the schema part was quoted (if this is a qualified identifier).

Source

pub fn table_canonical(&self) -> &str

Get the table part canonical form.

For simple identifiers, this is the same as canonical(). For qualified identifiers, this is just the table name portion.

Source

pub fn table_display(&self) -> &str

Get the table part display form.

For simple identifiers, this is the same as display(). For qualified identifiers, this is just the table name portion.

Source

pub fn is_table_quoted(&self) -> bool

Check if the table part was quoted.

For simple identifiers, this is the same as is_quoted(). For qualified identifiers, this indicates the quoting of the table part only.

Source

pub fn unquoted(name: &str) -> Self

Create an identifier that matches any case variation.

This creates an unquoted identifier from the given name, which will match any case variation of that name.

Source

pub fn quoted(name: &str) -> Self

Create an identifier that matches only the exact case.

This creates a quoted identifier from the given name, which will only match the exact same case.

Trait Implementations§

Source§

impl Clone for TableIdentifier

Source§

fn clone(&self) -> TableIdentifier

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 TableIdentifier

Source§

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

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

impl Display for TableIdentifier

Source§

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

Display uses the original user input form.

Source§

impl From<&str> for TableIdentifier

Source§

fn from(s: &str) -> Self

Convert from a string, assuming unquoted (case-insensitive).

Source§

impl From<String> for TableIdentifier

Source§

fn from(s: String) -> Self

Convert from a String, assuming unquoted (case-insensitive).

Source§

impl Hash for TableIdentifier

Source§

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

Hash based on canonical form for consistent HashMap behavior.

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 TableIdentifier

Source§

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

Two identifiers are equal if their canonical forms match.

1.0.0 · 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 Eq for TableIdentifier

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.