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: TableIdThe 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: StTableTypeWhether the table was created by a user or by the system.
table_access: StAccessThe visibility of the table.
schedule: Option<ScheduleSchema>The schedule for the table, if present.
Implementations§
Source§impl TableSchema
impl TableSchema
Sourcepub 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
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.
Sourcepub fn update_table_id(&mut self, id: TableId)
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.
Sourcepub fn into_columns(self) -> Vec<ColumnSchema>
pub fn into_columns(self) -> Vec<ColumnSchema>
Convert a table schema into a list of columns.
Sourcepub fn columns(&self) -> &[ColumnSchema]
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.
Sourcepub fn take_adjacent_schemas(
&mut self,
) -> (Vec<IndexSchema>, Vec<SequenceSchema>, Vec<ConstraintSchema>)
pub fn take_adjacent_schemas( &mut self, ) -> (Vec<IndexSchema>, Vec<SequenceSchema>, Vec<ConstraintSchema>)
Extracts all the Self::indexes, Self::sequences, and Self::constraints.
Sourcepub fn update_sequence(&mut self, of: SequenceSchema)
pub fn update_sequence(&mut self, of: SequenceSchema)
Add OR replace the SequenceSchema
Sourcepub fn remove_sequence(
&mut self,
sequence_id: SequenceId,
) -> Option<SequenceSchema>
pub fn remove_sequence( &mut self, sequence_id: SequenceId, ) -> Option<SequenceSchema>
Removes the given sequence_id
Sourcepub fn update_index(&mut self, of: IndexSchema)
pub fn update_index(&mut self, of: IndexSchema)
Add OR replace the IndexSchema
Sourcepub fn remove_index(&mut self, index_id: IndexId) -> Option<IndexSchema>
pub fn remove_index(&mut self, index_id: IndexId) -> Option<IndexSchema>
Removes the given index_id
Sourcepub fn update_constraint(&mut self, of: ConstraintSchema)
pub fn update_constraint(&mut self, of: ConstraintSchema)
Add OR replace the ConstraintSchema
Sourcepub fn remove_constraint(
&mut self,
constraint_id: ConstraintId,
) -> Option<ConstraintSchema>
pub fn remove_constraint( &mut self, constraint_id: ConstraintId, ) -> Option<ConstraintSchema>
Removes the given index_id
Sourcepub fn generate_cols_name(&self, columns: &ColList) -> String
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
Sourcepub fn get_column_by_field(&self, field: FieldName) -> Option<&ColumnSchema>
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.
Sourcepub fn get_columns<'a>(
&'a self,
columns: &'a ColList,
) -> impl 'a + Iterator<Item = (ColId, Option<&'a ColumnSchema>)>
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.
Sourcepub fn get_column(&self, pos: usize) -> Option<&ColumnSchema>
pub fn get_column(&self, pos: usize) -> Option<&ColumnSchema>
Get a reference to a column by its position (pos) in the table.
Sourcepub fn get_column_by_name(&self, col_name: &str) -> Option<&ColumnSchema>
pub fn get_column_by_name(&self, col_name: &str) -> Option<&ColumnSchema>
Check if the col_name exist on this TableSchema
Sourcepub fn get_column_id_by_name(&self, col_name: &str) -> Option<ColId>
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
Sourcepub fn col_list_for_index_id(&self, index_id: IndexId) -> ColList
pub fn col_list_for_index_id(&self, index_id: IndexId) -> ColList
Retrieve the column ids for this index id
Sourcepub fn is_unique(&self, cols: &ColList) -> bool
pub fn is_unique(&self, cols: &ColList) -> bool
Is there a unique constraint for this set of columns?
Sourcepub fn project(
&self,
indexes: impl Iterator<Item = ColId>,
) -> Result<Vec<&ColumnSchema>, InvalidFieldError>
pub fn project( &self, indexes: impl Iterator<Item = ColId>, ) -> Result<Vec<&ColumnSchema>, InvalidFieldError>
Project the fields from the supplied indexes.
Sourcepub fn project_not_empty(
&self,
indexes: ColList,
) -> Result<Vec<&ColumnSchema>, InvalidFieldError>
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.
Sourcepub fn get_row_type(&self) -> &ProductType
pub fn get_row_type(&self) -> &ProductType
IMPORTANT: Is required to have this cached to avoid a perf drop on datastore operations
Sourcepub fn into_row_type(self) -> ProductType
pub fn into_row_type(self) -> ProductType
Utility to avoid cloning in row_type_for_table
Sourcepub fn backcompat_constraints(&self) -> BTreeMap<ColList, Constraints>
pub fn backcompat_constraints(&self) -> BTreeMap<ColList, Constraints>
Get backwards-compatible constraints for this table.
This is closer to how TableSchema used to work.
Sourcepub fn backcompat_column_constraints(&self) -> BTreeMap<ColList, Constraints>
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.
Sourcepub fn pk(&self) -> Option<&ColumnSchema>
pub fn pk(&self) -> Option<&ColumnSchema>
Get the column corresponding to the primary key, if any.
Sourcepub fn validated(self) -> Result<Self, Vec<SchemaError>>
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.
Sourcepub fn janky_fix_column_defs(&mut self, module_def: &ModuleDef)
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.
Trait Implementations§
Source§impl Clone for TableSchema
impl Clone for TableSchema
Source§fn clone(&self) -> TableSchema
fn clone(&self) -> TableSchema
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TableSchema
impl Debug for TableSchema
Source§impl From<&TableSchema> for DbTable
impl From<&TableSchema> for DbTable
Source§fn from(value: &TableSchema) -> Self
fn from(value: &TableSchema) -> Self
Source§impl From<&TableSchema> for Header
impl From<&TableSchema> for Header
Source§fn from(value: &TableSchema) -> Self
fn from(value: &TableSchema) -> Self
Source§impl From<&TableSchema> for ProductType
impl From<&TableSchema> for ProductType
Source§fn from(value: &TableSchema) -> Self
fn from(value: &TableSchema) -> Self
Source§impl From<TableSchema> for Header
impl From<TableSchema> for Header
Source§fn from(schema: TableSchema) -> Self
fn from(schema: TableSchema) -> Self
Source§impl PartialEq for TableSchema
impl PartialEq for TableSchema
Source§impl Schema for TableSchema
impl Schema for TableSchema
Source§type ParentId = ()
type ParentId = ()
Id type corresponding to the parent of this schema type.
Set to () if there is no parent.impl Eq for TableSchema
impl StructuralPartialEq for TableSchema
Auto Trait Implementations§
impl Freeze for TableSchema
impl RefUnwindSafe for TableSchema
impl Send for TableSchema
impl Sync for TableSchema
impl Unpin for TableSchema
impl UnwindSafe for TableSchema
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