Struct TableSchema

Source
pub struct TableSchema {
    pub table_id: TableId,
    pub table_name: Box<str>,
    pub primary_key: Option<ColId>,
    pub indexes: Vec<IndexSchema>,
    pub constraints: Vec<ConstraintSchema>,
    pub sequences: Vec<SequenceSchema>,
    pub table_type: StTableType,
    pub table_access: StAccess,
    pub schedule: Option<ScheduleSchema>,
    /* private fields */
}
Expand description

A data structure representing the schema of a database table.

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

Fields§

§table_id: TableId

The unique identifier of the table within the database.

§table_name: Box<str>

The name of the table.

§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.

§indexes: Vec<IndexSchema>

The indexes on the table.

§constraints: Vec<ConstraintSchema>

The constraints on the table.

§sequences: Vec<SequenceSchema>

The sequences on the table.

§table_type: StTableType

Whether the table was created by a user or by the system.

§table_access: StAccess

The visibility of the table.

§schedule: Option<ScheduleSchema>

The schedule for the table, if present.

Implementations§

Source§

impl TableSchema

Source

pub fn new( table_id: TableId, table_name: Box<str>, columns: Vec<ColumnSchema>, indexes: Vec<IndexSchema>, constraints: Vec<ConstraintSchema>, sequences: Vec<SequenceSchema>, table_type: StTableType, table_access: StAccess, schedule: Option<ScheduleSchema>, primary_key: Option<ColId>, ) -> Self

Create a table schema.

Source

pub fn update_table_id(&mut self, id: TableId)

Update the table id of this schema. For use by the core database engine after assigning a table id.

Source

pub fn into_columns(self) -> Vec<ColumnSchema>

Convert a table schema into a list of columns.

Source

pub fn columns(&self) -> &[ColumnSchema]

Get the columns of the table. Only immutable access to the columns is provided. The ordering of the columns is significant. Columns are frequently identified by ColId, that is, position in this list.

Source

pub fn take_adjacent_schemas( &mut self, ) -> (Vec<IndexSchema>, Vec<SequenceSchema>, Vec<ConstraintSchema>)

Source

pub fn update_sequence(&mut self, of: SequenceSchema)

Add OR replace the SequenceSchema

Source

pub fn remove_sequence( &mut self, sequence_id: SequenceId, ) -> Option<SequenceSchema>

Removes the given sequence_id

Source

pub fn update_index(&mut self, of: IndexSchema)

Add OR replace the IndexSchema

Source

pub fn remove_index(&mut self, index_id: IndexId) -> Option<IndexSchema>

Removes the given index_id

Source

pub fn update_constraint(&mut self, of: ConstraintSchema)

Add OR replace the ConstraintSchema

Source

pub fn remove_constraint( &mut self, constraint_id: ConstraintId, ) -> Option<ConstraintSchema>

Removes the given index_id

Source

pub fn generate_cols_name(&self, columns: &ColList) -> String

Concatenate the column names from the columns

WARNING: If the ColId not exist, is skipped. TODO(Tyler): This should return an error and not allow this to be constructed if there is an invalid ColId

Source

pub fn get_column_by_field(&self, field: FieldName) -> Option<&ColumnSchema>

Check if the specified field exists in this TableSchema.

§Warning

This function ignores the table_id when searching for a column.

Source

pub fn get_columns<'a>( &'a self, columns: &'a ColList, ) -> impl 'a + Iterator<Item = (ColId, Option<&'a ColumnSchema>)>

Look up a list of columns by their positions in the table. Invalid column positions are permitted.

Source

pub fn get_column(&self, pos: usize) -> Option<&ColumnSchema>

Get a reference to a column by its position (pos) in the table.

Source

pub fn get_column_by_name(&self, col_name: &str) -> Option<&ColumnSchema>

Check if the col_name exist on this TableSchema

Source

pub fn get_column_id_by_name(&self, col_name: &str) -> Option<ColId>

Check if the col_name exist on this TableSchema

Warning: It ignores the table_name

Source

pub fn col_list_for_index_id(&self, index_id: IndexId) -> ColList

Retrieve the column ids for this index id

Source

pub fn is_unique(&self, cols: &ColList) -> bool

Is there a unique constraint for this set of columns?

Source

pub fn project( &self, indexes: impl Iterator<Item = ColId>, ) -> Result<Vec<&ColumnSchema>, InvalidFieldError>

Project the fields from the supplied indexes.

Source

pub fn project_not_empty( &self, indexes: ColList, ) -> Result<Vec<&ColumnSchema>, InvalidFieldError>

Utility for project the fields from the supplied indexes that is a ColList, used for when the list of field indexes have at least one value.

Source

pub fn get_row_type(&self) -> &ProductType

IMPORTANT: Is required to have this cached to avoid a perf drop on datastore operations

Source

pub fn into_row_type(self) -> ProductType

Utility to avoid cloning in row_type_for_table

Source

pub fn backcompat_constraints(&self) -> BTreeMap<ColList, Constraints>

Get backwards-compatible constraints for this table.

This is closer to how TableSchema used to work.

Source

pub fn backcompat_column_constraints(&self) -> BTreeMap<ColList, Constraints>

Get backwards-compatible constraints for this table.

Resolves the constraints per each column. If the column don’t have one, auto-generate Constraints::unset(). This guarantee all columns can be queried for it constraints.

Source

pub fn pk(&self) -> Option<&ColumnSchema>

Get the column corresponding to the primary key, if any.

Source

pub fn validated(self) -> Result<Self, Vec<SchemaError>>

Verify the definitions of this schema are valid:

  • Check all names are not empty
  • All columns exists
  • Only 1 PK
  • Only 1 sequence per column
  • Only Btree Indexes

Deprecated. This will eventually be replaced by the schema crate.

Source

pub fn janky_fix_column_defs(&mut self, module_def: &ModuleDef)

The C# and Rust SDKs are inconsistent about whether v8 column defs store resolved or unresolved algebraic types. This method works around this problem by copying the column types from the module def into the table schema. It can be removed once v8 is removed, since v9 will reject modules with an inconsistency like this.

Source

pub fn normalize(&mut self)

Normalize a TableSchema. The result is semantically equivalent, but may have reordered indexes, constraints, or sequences. Columns will not be reordered.

Trait Implementations§

Source§

impl Clone for TableSchema

Source§

fn clone(&self) -> TableSchema

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 TableSchema

Source§

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

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

impl From<&TableSchema> for DbTable

Source§

fn from(value: &TableSchema) -> Self

Converts to this type from the input type.
Source§

impl From<&TableSchema> for Header

Source§

fn from(value: &TableSchema) -> Self

Converts to this type from the input type.
Source§

impl From<&TableSchema> for ProductType

Source§

fn from(value: &TableSchema) -> Self

Converts to this type from the input type.
Source§

impl From<TableSchema> for Header

Source§

fn from(schema: TableSchema) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for TableSchema

Source§

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

Source§

type Def = TableDef

The Def type corresponding to this schema type.
Source§

type Id = TableId

The Id type corresponding to this schema type.
Source§

type ParentId = ()

The Id type corresponding to the parent of this schema type. Set to () if there is no parent.
Source§

fn from_module_def( module_def: &ModuleDef, def: &Self::Def, _parent_id: Self::ParentId, table_id: Self::Id, ) -> Self

Construct a schema entity from a validated ModuleDef. Panics if module_def does not contain def. Read more
Source§

fn check_compatible( &self, module_def: &ModuleDef, def: &Self::Def, ) -> Result<(), Error>

Check that a schema entity is compatible with a definition.
Source§

impl Eq for TableSchema

Source§

impl StructuralPartialEq for TableSchema

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.