Struct spacetimedb_sats::db::def::TableDef
source · pub struct TableDef {
pub table_name: String,
pub columns: Vec<ColumnDef>,
pub indexes: Vec<IndexDef>,
pub constraints: Vec<ConstraintDef>,
pub sequences: Vec<SequenceDef>,
pub table_type: StTableType,
pub table_access: StAccess,
}
Expand description
A data structure representing the definition of a database table.
This struct holds information about the table, including its name, columns, indexes, constraints, sequences, type, and access rights.
Fields§
§table_name: String
§columns: Vec<ColumnDef>
§indexes: Vec<IndexDef>
§constraints: Vec<ConstraintDef>
§sequences: Vec<SequenceDef>
§table_type: StTableType
§table_access: StAccess
Implementations§
source§impl TableDef
impl TableDef
sourcepub fn new(table_name: String, columns: Vec<ColumnDef>) -> Self
pub fn new(table_name: String, columns: Vec<ColumnDef>) -> Self
Create a new TableDef
instance with the specified table_name
and columns
.
§Parameters
table_name
: The name of the table.columns
: Avec
ofColumnDef
instances representing the columns of the table.
sourcepub fn with_type(self, table_type: StTableType) -> Self
pub fn with_type(self, table_type: StTableType) -> Self
Set the type of the table and return a new TableDef
instance with the updated type.
sourcepub fn with_access(self, table_access: StAccess) -> Self
pub fn with_access(self, table_access: StAccess) -> Self
Set the access rights for the table and return a new TableDef
instance with the updated access rights.
sourcepub fn with_constraints(self, constraints: Vec<ConstraintDef>) -> Self
pub fn with_constraints(self, constraints: Vec<ConstraintDef>) -> Self
Set the constraints for the table and return a new TableDef
instance with the updated constraints.
sourcepub fn with_column_constraint(
self,
kind: Constraints,
columns: impl Into<ColList>
) -> Self
pub fn with_column_constraint( self, kind: Constraints, columns: impl Into<ColList> ) -> Self
Generate a ConstraintDef using the supplied columns
.
sourcepub fn with_indexes(self, indexes: Vec<IndexDef>) -> Self
pub fn with_indexes(self, indexes: Vec<IndexDef>) -> Self
Set the indexes for the table and return a new TableDef
instance with the updated indexes.
sourcepub fn with_column_index(
self,
columns: impl Into<ColList>,
is_unique: bool
) -> Self
pub fn with_column_index( self, columns: impl Into<ColList>, is_unique: bool ) -> Self
Generate a IndexDef using the supplied columns
.
sourcepub fn with_sequences(self, sequences: Vec<SequenceDef>) -> Self
pub fn with_sequences(self, sequences: Vec<SequenceDef>) -> Self
Set the sequences for the table and return a new TableDef
instance with the updated sequences.
sourcepub fn with_column_sequence(self, columns: ColId) -> Self
pub fn with_column_sequence(self, columns: ColId) -> Self
Generate a SequenceDef using the supplied columns
.
sourcepub fn from_product(table_name: &str, row: ProductType) -> Self
pub fn from_product(table_name: &str, row: ProductType) -> Self
Create a TableDef
from a product type and table name.
NOTE: If the [ProductType.name] is None
then it auto-generate a name like col_{col_pos}
sourcepub fn generated_indexes(&self) -> impl Iterator<Item = IndexDef> + '_
pub fn generated_indexes(&self) -> impl Iterator<Item = IndexDef> + '_
Get an iterator deriving IndexDef from the constraints that require them like UNIQUE
.
It looks into Self::constraints for possible duplicates and remove them from the result
sourcepub fn generated_sequences(&self) -> impl Iterator<Item = SequenceDef> + '_
pub fn generated_sequences(&self) -> impl Iterator<Item = SequenceDef> + '_
Get an iterator deriving SequenceDef from the constraints that require them like IDENTITY
.
It looks into Self::constraints for possible duplicates and remove them from the result
sourcepub fn generated_constraints(&self) -> impl Iterator<Item = ConstraintDef> + '_
pub fn generated_constraints(&self) -> impl Iterator<Item = ConstraintDef> + '_
Get an iterator deriving ConstraintDef from the indexes that require them like UNIQUE
.
It looks into Self::constraints for possible duplicates and remove them from the result
sourcepub fn into_schema(self, table_id: TableId) -> TableSchema
pub fn into_schema(self, table_id: TableId) -> TableSchema
Create a new TableSchema from Self and a table id
.
sourcepub fn get_column_by_field(&self, field: &FieldName) -> Option<&ColumnDef>
pub fn get_column_by_field(&self, field: &FieldName) -> Option<&ColumnDef>
pub fn get_column(&self, pos: usize) -> Option<&ColumnDef>
sourcepub fn get_column_by_name(&self, col_name: &str) -> Option<&ColumnDef>
pub fn get_column_by_name(&self, col_name: &str) -> Option<&ColumnDef>
Check if the col_name
exist on this TableSchema
Warning: It ignores the table_name
Trait Implementations§
source§impl<'de> Deserialize<'de> for TableDef
impl<'de> Deserialize<'de> for TableDef
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
deserializer
.source§impl From<TableSchema> for TableDef
impl From<TableSchema> for TableDef
source§fn from(value: TableSchema) -> Self
fn from(value: TableSchema) -> Self
source§impl Ord for TableDef
impl Ord for TableDef
source§impl PartialEq for TableDef
impl PartialEq for TableDef
source§impl PartialOrd for TableDef
impl PartialOrd for TableDef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for TableDef
impl StructuralPartialEq for TableDef
Auto Trait Implementations§
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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Satn for T
impl<T> Satn for T
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
f
.source§fn fmt_psql(&self, f: &mut Formatter<'_>) -> Result
fn fmt_psql(&self, f: &mut Formatter<'_>) -> Result
f
.source§fn to_satn(&self) -> String
fn to_satn(&self) -> String
String
.source§fn to_satn_pretty(&self) -> String
fn to_satn_pretty(&self) -> String
String
.