pub struct TableSchema {
    pub table_id: TableId,
    pub table_name: String,
    pub indexes: Vec<IndexSchema>,
    pub constraints: Vec<ConstraintSchema>,
    pub sequences: Vec<SequenceSchema>,
    pub table_type: StTableType,
    pub table_access: StAccess,
    /* 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§table_name: String§indexes: Vec<IndexSchema>§constraints: Vec<ConstraintSchema>§sequences: Vec<SequenceSchema>§table_type: StTableType§table_access: StAccess

Implementations§

source§

impl TableSchema

source

pub fn new( table_id: TableId, table_name: String, columns: Vec<ColumnSchema>, indexes: Vec<IndexSchema>, constraints: Vec<ConstraintSchema>, sequences: Vec<SequenceSchema>, table_type: StTableType, table_access: StAccess ) -> Self

source

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

IMPORTANT: Ban changes from outside so Self::row_type won’t get invalidated.

source

pub fn clear_adjacent_schemas(&mut self)

source

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

Add OR replace the SequenceSchema

source

pub fn remove_sequence(&mut self, sequence_id: SequenceId)

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)

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)

Removes the given index_id

source

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

Check if the specified field exists in this TableSchema.

This function can handle both named and positional fields.

§Warning

This function ignores the table_name when searching for a column.

source

pub fn get_columns( &self, columns: &ColList ) -> Vec<(ColId, Option<&ColumnSchema>)>

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

Warning: It ignores the table_name

source

pub fn get_index_by_field(&self, field: &FieldName) -> Option<&IndexSchema>

Check if there is an index for this FieldName

Warning: It ignores the table_name

source

pub fn normalize_field(&self, or_use: &TableField<'_>) -> FieldName

Turn a TableField that could be an unqualified field id into table.id

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 get_constraints(&self) -> Vec<(ColList, Constraints)>

source

pub fn from_def(table_id: TableId, schema: TableDef) -> Self

Create a new TableSchema from a TableDef and a table_id.

§Parameters
  • table_id: The unique identifier for the table.
  • schema: The TableDef containing the schema information.
source

pub fn column_constraints_iter( &self ) -> impl Iterator<Item = (ColList, &Constraints)>

source

pub fn column_constraints(&self) -> HashMap<ColList, Constraints>

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>

Find the pk column. Because we run Self::validated, only exist one pk.

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

Trait Implementations§

source§

impl Clone for TableSchema

source§

fn clone(&self) -> TableSchema

Returns a copy 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 TableDef

source§

fn from(value: TableSchema) -> Self

Converts to this type from the input type.
source§

impl PartialEq for TableSchema

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more