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

source

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: A vec of ColumnDef instances representing the columns of the table.
source

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.

source

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.

source

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.

source

pub fn with_column_constraint( self, kind: Constraints, columns: impl Into<ColList> ) -> Self

Generate a ConstraintDef using the supplied columns.

source

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.

source

pub fn with_column_index( self, columns: impl Into<ColList>, is_unique: bool ) -> Self

Generate a IndexDef using the supplied columns.

source

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.

source

pub fn with_column_sequence(self, columns: ColId) -> Self

Generate a SequenceDef using the supplied columns.

source

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}

source

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

source

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

source

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

source

pub fn into_schema(self, table_id: TableId) -> TableSchema

Create a new TableSchema from Self and a table id.

source

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

Check if the name of the FieldName exist on this TableDef

Warning: It ignores the table_name

source

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

source

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 Clone for TableDef

source§

fn clone(&self) -> TableDef

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 TableDef

source§

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

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

impl<'de> Deserialize<'de> for TableDef

source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given deserializer.
source§

impl From<TableSchema> for TableDef

source§

fn from(value: TableSchema) -> Self

Converts to this type from the input type.
source§

impl Ord for TableDef

source§

fn cmp(&self, other: &TableDef) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for TableDef

source§

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

source§

fn partial_cmp(&self, other: &TableDef) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for TableDef

source§

fn serialize<S: Serializer>(&self, __serializer: S) -> Result<S::Ok, S::Error>

Serialize self in the data format of S using the provided serializer.
source§

impl Eq for TableDef

source§

impl StructuralPartialEq for TableDef

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> Satn for T
where T: Serialize + ?Sized,

source§

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

Formats the value using the SATN data format into the formatter f.
source§

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

Formats the value using the postgres SATN data format into the formatter f.
source§

fn to_satn(&self) -> String

Formats the value using the SATN data format into the returned String.
source§

fn to_satn_pretty(&self) -> String

Pretty prints the value using the SATN data format into the returned String.
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
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,