pub struct TableSpec {
pub name: TableName,
pub title: String,
pub fields: Vec<FieldSpec>,
pub indexes: Vec<TableIndexSpec>,
pub checks: Vec<TableCheckSpec>,
pub foreign_keys: Vec<TableForeignKeySpec>,
pub opaque_columns: Vec<TableOpaqueColumnSpec>,
pub datasource: Option<DatasourceId>,
/* private fields */
}Expand description
表及其唯一字段定义。
Fields§
§name: TableName表名。
title: String用户可见名称。
fields: Vec<FieldSpec>字段集合。
indexes: Vec<TableIndexSpec>表级复合索引。
checks: Vec<TableCheckSpec>表级 CHECK 约束。
foreign_keys: Vec<TableForeignKeySpec>表级外键约束。
opaque_columns: Vec<TableOpaqueColumnSpec>框架不建模的存量列(仅 PostgreSQL)。
datasource: Option<DatasourceId>表所属逻辑数据源;None 表示使用模块/默认数据源。
Implementations§
Source§impl TableSpec
impl TableSpec
Sourcepub fn datasource(self, id: DatasourceId) -> Self
pub fn datasource(self, id: DatasourceId) -> Self
设置表所属逻辑数据源。
Sourcepub fn unique(self, fields: impl IntoIterator<Item = FieldRef>) -> Self
pub fn unique(self, fields: impl IntoIterator<Item = FieldRef>) -> Self
添加复合唯一索引。
Sourcepub fn unique_named(
self,
name: impl Into<String>,
fields: impl IntoIterator<Item = FieldRef>,
) -> Self
pub fn unique_named( self, name: impl Into<String>, fields: impl IntoIterator<Item = FieldRef>, ) -> Self
添加指定名称的复合唯一索引。
Sourcepub fn index(self, fields: impl IntoIterator<Item = FieldRef>) -> Self
pub fn index(self, fields: impl IntoIterator<Item = FieldRef>) -> Self
添加复合普通索引。
Sourcepub fn index_named(
self,
name: impl Into<String>,
fields: impl IntoIterator<Item = FieldRef>,
) -> Self
pub fn index_named( self, name: impl Into<String>, fields: impl IntoIterator<Item = FieldRef>, ) -> Self
添加指定名称的复合普通索引。
Sourcepub fn partial_index(
self,
name: impl Into<String>,
fields: impl IntoIterator<Item = FieldRef>,
predicate: impl Into<String>,
) -> Self
pub fn partial_index( self, name: impl Into<String>, fields: impl IntoIterator<Item = FieldRef>, predicate: impl Into<String>, ) -> Self
添加带 WHERE 谓词的 PostgreSQL 部分索引。
Sourcepub fn partial_unique_named(
self,
name: impl Into<String>,
fields: impl IntoIterator<Item = FieldRef>,
predicate: impl Into<String>,
) -> Self
pub fn partial_unique_named( self, name: impl Into<String>, fields: impl IntoIterator<Item = FieldRef>, predicate: impl Into<String>, ) -> Self
添加带 WHERE 谓词的 PostgreSQL 部分唯一索引。
Sourcepub fn expression_index(
self,
name: impl Into<String>,
expressions: impl IntoIterator<Item = impl Into<String>>,
unique: bool,
) -> Self
pub fn expression_index( self, name: impl Into<String>, expressions: impl IntoIterator<Item = impl Into<String>>, unique: bool, ) -> Self
添加表达式索引(如 lower(email))。
Sourcepub fn check_named(
self,
name: impl Into<String>,
expression: impl Into<String>,
) -> Self
pub fn check_named( self, name: impl Into<String>, expression: impl Into<String>, ) -> Self
添加指定名称的 CHECK 约束。
Sourcepub fn foreign_key_named(
self,
name: impl Into<String>,
fields: impl IntoIterator<Item = FieldRef>,
referenced_fields: impl IntoIterator<Item = FieldRef>,
) -> Self
pub fn foreign_key_named( self, name: impl Into<String>, fields: impl IntoIterator<Item = FieldRef>, referenced_fields: impl IntoIterator<Item = FieldRef>, ) -> Self
添加指定名称的复合外键;更新和删除规则固定为 RESTRICT。
Sourcepub fn opaque_column(
self,
name: impl Into<String>,
sql_type: impl Into<String>,
) -> Self
pub fn opaque_column( self, name: impl Into<String>, sql_type: impl Into<String>, ) -> Self
声明一个框架不建模的存量列(仅 PostgreSQL)。
Sourcepub fn table_definition(&self) -> Result<TableDefinition, BaseError>
pub fn table_definition(&self) -> Result<TableDefinition, BaseError>
生成 schema 同步和 TableQuery 使用的不可变执行产物。
Trait Implementations§
impl Eq for TableSpec
impl StructuralPartialEq for TableSpec
Auto Trait Implementations§
impl Forget for TableSpec
impl Freeze for TableSpec
impl Move for TableSpec
impl RefUnwindSafe for TableSpec
impl Send for TableSpec
impl Sync for TableSpec
impl Unpin for TableSpec
impl UnsafeUnpin for TableSpec
impl UnwindSafe for TableSpec
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
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
Compare self to
key and return true if they are equal.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> 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> ⓘ
Converts
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> ⓘ
Converts
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