Struct TableDef

Source
#[non_exhaustive]
pub struct TableDef { pub name: Identifier, pub product_type_ref: AlgebraicTypeRef, pub primary_key: Option<ColId>, pub columns: Vec<ColumnDef>, pub indexes: StrMap<IndexDef>, pub constraints: StrMap<ConstraintDef>, pub sequences: StrMap<SequenceDef>, pub schedule: Option<ScheduleDef>, pub table_type: TableType, pub table_access: TableAccess, }
Expand description

A data structure representing the validated definition of a database table.

Cannot be created directly. Construct a ModuleDef by validating a RawModuleDef instead, and then access the tables from there.

This struct holds information about the table, including its name, columns, indexes, constraints, sequences, type, and access rights.

Validation rules:

  • The table name must be a valid identifier.
  • The table’s columns must be sorted according to [crate::db::ordering::canonical_ordering].
  • The table’s indexes, constraints, and sequences must be sorted by their keys.
  • The table’s column types may refer only to types in the containing DatabaseDef’s typespace.
  • The table’s column names must be unique.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: Identifier

The name of the table. Unique within a module, acts as the table’s identifier. Must be a valid [crate::db::identifier::Identifier].

§product_type_ref: AlgebraicTypeRef

A reference to a ProductType containing the columns of this table. This is the single source of truth for the table’s columns. All elements of the ProductType must have names.

Like all types in the module, this must have the default element ordering, UNLESS a custom ordering is declared via ModuleDef.misc_exports for this type.

§primary_key: Option<ColId>

The primary key of the table, if present. Must refer to a valid column.

Currently, there must be a unique constraint and an index corresponding to the primary key. Eventually, we may remove the requirement for an index.

The database engine does not actually care about this, but client code generation does.

§columns: Vec<ColumnDef>

The columns of this table. This stores the information in product_type_ref in a more convenient-to-access format.

§indexes: StrMap<IndexDef>

The indices on the table, indexed by name.

§constraints: StrMap<ConstraintDef>

The unique constraints on the table, indexed by name.

§sequences: StrMap<SequenceDef>

The sequences for the table, indexed by name.

§schedule: Option<ScheduleDef>

The schedule for the table, if present.

§table_type: TableType

Whether this is a system- or user-created table.

§table_access: TableAccess

Whether this table is public or private.

Implementations§

Source§

impl TableDef

Source

pub fn get_column(&self, id: ColId) -> Option<&ColumnDef>

Get a column of the TableDef.

Source

pub fn get_column_by_name(&self, name: &Identifier) -> Option<&ColumnDef>

Get a column by the column’s name.

Trait Implementations§

Source§

impl Clone for TableDef

Source§

fn clone(&self) -> TableDef

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 TableDef

Source§

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

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

impl From<TableDef> for RawTableDefV9

Source§

fn from(val: TableDef) -> Self

Converts to this type from the input type.
Source§

impl ModuleDefLookup for TableDef

Source§

type Key<'a> = &'a Identifier

A reference to a definition of this type within a module def. This reference should be portable across migrations.
Source§

fn key(&self) -> Self::Key<'_>

Get a reference to this definition.
Source§

fn lookup<'a>(module_def: &'a ModuleDef, key: Self::Key<'_>) -> Option<&'a Self>

Look up this entity in the module def.
Source§

impl PartialEq for TableDef

Source§

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

Tests for self and other values to be equal, and is used by ==.
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 TableDef

Source§

impl StructuralPartialEq for TableDef

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.