Skip to main content

TableRef

Struct TableRef 

Source
pub struct TableRef {
    pub expression: Option<Expr>,
    pub alias: Option<Cow<'static, str>>,
    pub columns: Vec<Cow<'static, str>>,
    pub only: bool,
    pub lateral: bool,
    pub with_ordinality: bool,
    pub partitions: Vec<Cow<'static, str>>,
    pub index_hints: Vec<IndexHint>,
    pub indexed_by: Option<IndexedBy>,
    pub joins: Vec<Join>,
}
Expand description

A from_item: a table, a sub-select, a function call or a CTE name, plus every decoration the three dialects hang off one, plus its joins.

[ONLY] [LATERAL] expr [WITH ORDINALITY] [PARTITION (…)] [[AS] alias [(cols)]]
       [index hints] [INDEXED BY … | NOT INDEXED] [joins]

The order is PostgreSQL’s from_item production (https://www.postgresql.org/docs/17/sql-select.html) with MySQL’s table_reference (https://dev.mysql.com/doc/refman/8.4/en/join.html) and SQLite’s qualified-table-name slotted into the positions those grammars put them in.

Every dialect’s decorations live on this one struct rather than in three near-identical copies, because a shared Join has to be able to hold a TableRef whatever dialect it came from. Which of them a dialect permits is decided by which mods that dialect exports — not by this shape. The dialect-specific fields are labelled below.

The same struct is also an INSERT’s target, where columns is the insert column list, and an UPDATE’s or DELETE’s table.

Fields§

§expression: Option<Expr>

The table, sub-select, function call or CTE name.

§alias: Option<Cow<'static, str>>

The table alias, quoted on output.

§columns: Vec<Cow<'static, str>>

Column aliases — or, for an INSERT, the insert column list. Quoted.

§only: bool

PostgreSQL ONLY: do not include descendant tables.

§lateral: bool

PostgreSQL and MySQL LATERAL.

§with_ordinality: bool

PostgreSQL WITH ORDINALITY, for a set-returning function.

§partitions: Vec<Cow<'static, str>>

MySQL PARTITION (…). Quoted.

§index_hints: Vec<IndexHint>

MySQL USE/FORCE/IGNORE INDEX.

§indexed_by: Option<IndexedBy>

SQLite INDEXED BY … / NOT INDEXED.

§joins: Vec<Join>

Joins hanging off this item, rendered after all of its decorations.

Implementations§

Source§

impl TableRef

Source

pub fn new(table: impl IntoExpr) -> Self

A plain table reference with no decorations.

Source

pub fn set_table(&mut self, table: impl IntoExpr)

Replace the table.

Source

pub fn set_alias(&mut self, alias: impl Into<Cow<'static, str>>)

Set the alias. Column aliases are set_columns, so that neither has to be named to set the other.

Source

pub fn set_columns( &mut self, columns: impl IntoIterator<Item = impl Into<Cow<'static, str>>>, )

Set the column aliases — or, for an INSERT, the insert column list.

Source

pub fn append_join(&mut self, join: Join)

Append a join.

Source

pub fn append_partition( &mut self, names: impl IntoIterator<Item = impl Into<Cow<'static, str>>>, )

Append MySQL partition names.

Source

pub fn append_index_hint(&mut self, hint: IndexHint)

Append a MySQL index hint.

Source

pub fn is_empty(&self) -> bool

Whether there is no table at all — what a query tests before writing FROM. A TableRef that has joins but no table of its own is still unwritable, so only the table is consulted.

Trait Implementations§

Source§

impl Clone for TableRef

Source§

fn clone(&self) -> TableRef

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 TableRef

Source§

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

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

impl Default for TableRef

Source§

fn default() -> TableRef

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

impl Expression for TableRef

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Append this fragment to w. Read more
Source§

impl HasJoins for TableRef

Source§

fn joins_mut(&mut self) -> &mut Vec<Join>

The join list to modify.
Source§

impl HasTableRef for TableRef

Source§

fn table_ref_mut(&mut self) -> &mut TableRef

The table reference to modify.

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.