pub struct Table { /* private fields */ }Expand description
Schema-first 表构建器。
Implementations§
Source§impl Table
impl Table
Sourcepub fn datasource(self, id: DatasourceId) -> Self
pub fn datasource(self, id: DatasourceId) -> Self
设置表所属逻辑数据源(默认 default)。
Sourcepub fn primary_key_order(self, order: Vec<String>) -> Self
pub fn primary_key_order(self, order: Vec<String>) -> Self
覆盖复合主键的列顺序(用于抵消字段排序)。
Sourcepub fn fields<I>(self, fields: I) -> Selfwhere
I: IntoIterator<Item = Field>,
pub fn fields<I>(self, fields: I) -> Selfwhere
I: IntoIterator<Item = Field>,
批量添加字段;支持数组、Vec 和任意字段迭代器。
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)。
该列必须已存在且 format_type 与 sql_type 一致;框架不改写、不读取、
不写入,也不投影到通用 CRUD/UI。用于 inet、citext、自定义 domain 等
无法安全映射为通用字段类型的列。
Sourcepub fn unique_named<I, C>(self, name: impl Into<String>, fields: I) -> Self
pub fn unique_named<I, C>(self, name: impl Into<String>, fields: I) -> Self
添加指定名称的复合唯一索引。
Sourcepub fn unique_nulls_not_distinct<I, C>(self, fields: I) -> Self
pub fn unique_nulls_not_distinct<I, C>(self, fields: I) -> Self
添加复合唯一索引,并声明 PostgreSQL 15+ 的 NULLS NOT DISTINCT 语义。
空值互不异:两行该索引列均为 NULL 时会触发唯一冲突。仅 PostgreSQL 支持; MySQL 在 schema 同步时明确拒绝该标志。
Sourcepub fn unique_named_nulls_not_distinct<I, C>(
self,
name: impl Into<String>,
fields: I,
) -> Self
pub fn unique_named_nulls_not_distinct<I, C>( self, name: impl Into<String>, fields: I, ) -> Self
添加指定名称的复合唯一索引,并声明 NULLS NOT DISTINCT 语义。
Sourcepub fn index_named<I, C>(self, name: impl Into<String>, fields: I) -> Self
pub fn index_named<I, C>(self, name: impl Into<String>, fields: I) -> Self
添加指定名称的复合普通索引。
Sourcepub fn index_spec<I, C, S>(
self,
name: Option<String>,
fields: I,
expressions: impl IntoIterator<Item = S>,
predicate: Option<String>,
unique: bool,
nulls_not_distinct: bool,
) -> Self
pub fn index_spec<I, C, S>( self, name: Option<String>, fields: I, expressions: impl IntoIterator<Item = S>, predicate: Option<String>, unique: bool, nulls_not_distinct: bool, ) -> Self
添加带受信表达式键与/或部分索引谓词的索引(仅 PostgreSQL 支持)。
fields 与 expressions 至少一个非空;predicate 是 WHERE 后原样
渲染的受信 SQL 表达式。MySQL 在 schema 同步时明确拒绝部分/表达式索引。
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
添加指定名称的 MySQL CHECK 约束。
表达式属于受信任的应用定义,不得来自请求或运行时配置。
Sourcepub fn foreign_key_named<I, C, R, RC>(
self,
name: impl Into<String>,
columns: I,
referenced_table: impl Into<String>,
referenced_columns: R,
) -> Selfwhere
I: IntoIterator<Item = C>,
C: Into<ColumnName>,
R: IntoIterator<Item = RC>,
RC: Into<ColumnName>,
pub fn foreign_key_named<I, C, R, RC>(
self,
name: impl Into<String>,
columns: I,
referenced_table: impl Into<String>,
referenced_columns: R,
) -> Selfwhere
I: IntoIterator<Item = C>,
C: Into<ColumnName>,
R: IntoIterator<Item = RC>,
RC: Into<ColumnName>,
添加指定名称的复合外键;更新和删除规则固定为 RESTRICT。
Sourcepub fn default_order(self, order: Order) -> Self
pub fn default_order(self, order: Order) -> Self
设置首个默认排序规则。
Sourcepub fn then_order(self, order: Order) -> Self
pub fn then_order(self, order: Order) -> Self
追加默认排序规则。
Sourcepub fn build(self) -> Result<TableDefinition, BaseError>
pub fn build(self) -> Result<TableDefinition, BaseError>
校验并生成不可变表定义。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Table
impl !UnwindSafe for Table
impl Forget for Table
impl Freeze for Table
impl Move for Table
impl Send for Table
impl Sync for Table
impl Unpin for Table
impl UnsafeUnpin for Table
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<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