pub struct LogicalModel {
pub name: String,
pub tables: IndexMap<TableId, Table>,
/* private fields */
}Expand description
The full logical (relational) model.
Fields§
§name: StringDatabase / schema name.
tables: IndexMap<TableId, Table>Tables, keyed for O(1) lookup; iteration order is insertion order.
Implementations§
Source§impl LogicalModel
impl LogicalModel
Sourcepub fn table_mut(&mut self, id: TableId) -> Result<&mut Table>
pub fn table_mut(&mut self, id: TableId) -> Result<&mut Table>
Mutably borrow a table by handle.
Sourcepub fn add_column(
&mut self,
table: TableId,
name: impl Into<String>,
data_type: DataType,
) -> Result<ColumnId>
pub fn add_column( &mut self, table: TableId, name: impl Into<String>, data_type: DataType, ) -> Result<ColumnId>
Append a new column to table.
Sourcepub fn set_primary_key(
&mut self,
table: TableId,
columns: Vec<ColumnId>,
) -> Result<ConstraintId>
pub fn set_primary_key( &mut self, table: TableId, columns: Vec<ColumnId>, ) -> Result<ConstraintId>
Add (or replace) a primary-key constraint on table.
Sourcepub fn add_foreign_key(
&mut self,
table: TableId,
fk: ForeignKey,
) -> Result<ConstraintId>
pub fn add_foreign_key( &mut self, table: TableId, fk: ForeignKey, ) -> Result<ConstraintId>
Add a foreign-key constraint on table.
Sourcepub fn add_unique(
&mut self,
table: TableId,
columns: Vec<ColumnId>,
) -> Result<ConstraintId>
pub fn add_unique( &mut self, table: TableId, columns: Vec<ColumnId>, ) -> Result<ConstraintId>
Add a UNIQUE constraint over the given columns.
Source§impl LogicalModel
impl LogicalModel
Sourcepub fn to_sql(&self, dialect: SqlDialect) -> String
pub fn to_sql(&self, dialect: SqlDialect) -> String
Render this logical model as a SQL DDL script for the given dialect.
Tables are emitted in author order, with primary keys inline and
foreign keys deferred to ALTER TABLE statements at the bottom of the
script (so that forward references between tables resolve cleanly).
Trait Implementations§
Source§impl Clone for LogicalModel
impl Clone for LogicalModel
Source§fn clone(&self) -> LogicalModel
fn clone(&self) -> LogicalModel
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LogicalModel
impl Debug for LogicalModel
Source§impl Default for LogicalModel
impl Default for LogicalModel
Source§fn default() -> LogicalModel
fn default() -> LogicalModel
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for LogicalModel
impl<'de> Deserialize<'de> for LogicalModel
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for LogicalModel
impl RefUnwindSafe for LogicalModel
impl Send for LogicalModel
impl Sync for LogicalModel
impl Unpin for LogicalModel
impl UnsafeUnpin for LogicalModel
impl UnwindSafe for LogicalModel
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
Mutably borrows from an owned value. Read more