pub struct TableSchema {
pub name: String,
pub columns: Vec<ColumnDef>,
pub indexes: Vec<IndexDef>,
pub foreign_keys: Vec<ForeignKeyDef>,
}Expand description
表结构定义
Fields§
§name: String表名
columns: Vec<ColumnDef>列定义列表
indexes: Vec<IndexDef>索引定义列表
foreign_keys: Vec<ForeignKeyDef>外键约束列表
Implementations§
Source§impl TableSchema
impl TableSchema
Sourcepub fn foreign_key(self, fk: ForeignKeyDef) -> Self
pub fn foreign_key(self, fk: ForeignKeyDef) -> Self
添加外键约束
Sourcepub fn to_drop_sql(&self) -> String
pub fn to_drop_sql(&self) -> String
生成删表 SQL
Sourcepub fn primary_key(&self) -> Option<&ColumnDef>
pub fn primary_key(&self) -> Option<&ColumnDef>
获取主键列
Sourcepub fn get_column(&self, name: &str) -> Option<&ColumnDef>
pub fn get_column(&self, name: &str) -> Option<&ColumnDef>
根据名称获取列
Source§impl TableSchema
impl TableSchema
Sourcepub fn to_create_sql(&self) -> String
pub fn to_create_sql(&self) -> String
生成建表 SQL(使用当前数据库类型)
Sourcepub fn to_create_sql_for(&self, db_type: DatabaseType) -> String
pub fn to_create_sql_for(&self, db_type: DatabaseType) -> String
生成指定数据库类型的建表 SQL
Sourcepub fn to_create_indexes_sql(&self) -> Vec<String>
pub fn to_create_indexes_sql(&self) -> Vec<String>
生成所有创建索引的 SQL(使用当前数据库类型)
Sourcepub fn to_create_indexes_sql_for(&self, db_type: DatabaseType) -> Vec<String>
pub fn to_create_indexes_sql_for(&self, db_type: DatabaseType) -> Vec<String>
生成所有创建索引的 SQL(指定数据库类型)
Sourcepub fn to_full_create_sql(&self) -> Vec<String>
pub fn to_full_create_sql(&self) -> Vec<String>
生成完整的建表和索引 SQL(使用当前数据库类型)
Sourcepub fn to_full_create_sql_for(&self, db_type: DatabaseType) -> Vec<String>
pub fn to_full_create_sql_for(&self, db_type: DatabaseType) -> Vec<String>
生成完整的建表和索引 SQL(指定数据库类型)
Trait Implementations§
Source§impl Clone for TableSchema
impl Clone for TableSchema
Source§fn clone(&self) -> TableSchema
fn clone(&self) -> TableSchema
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 TableSchema
impl Debug for TableSchema
Source§impl<'de> Deserialize<'de> for TableSchema
impl<'de> Deserialize<'de> for TableSchema
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 TableSchema
impl RefUnwindSafe for TableSchema
impl Send for TableSchema
impl Sync for TableSchema
impl Unpin for TableSchema
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more