#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: IdentifierThe 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: AlgebraicTypeRefA 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: TableTypeWhether this is a system- or user-created table.
table_access: TableAccessWhether this table is public or private.
Implementations§
Source§impl TableDef
impl TableDef
Sourcepub fn get_column(&self, id: ColId) -> Option<&ColumnDef>
pub fn get_column(&self, id: ColId) -> Option<&ColumnDef>
Get a column of the TableDef.
Sourcepub fn get_column_by_name(&self, name: &Identifier) -> Option<&ColumnDef>
pub fn get_column_by_name(&self, name: &Identifier) -> Option<&ColumnDef>
Get a column by the column’s name.
Trait Implementations§
Source§impl From<TableDef> for RawTableDefV9
impl From<TableDef> for RawTableDefV9
Source§impl ModuleDefLookup for TableDef
impl ModuleDefLookup for TableDef
Source§type Key<'a> = &'a Identifier
type Key<'a> = &'a Identifier
impl Eq for TableDef
impl StructuralPartialEq for TableDef
Auto Trait Implementations§
impl Freeze for TableDef
impl RefUnwindSafe for TableDef
impl Send for TableDef
impl Sync for TableDef
impl Unpin for TableDef
impl UnwindSafe for TableDef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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