Skip to main content

Table

Struct Table 

Source
pub struct Table { /* private fields */ }
Expand description

Schema-first 表构建器。

Implementations§

Source§

impl Table

Source

pub fn new(name: impl Into<String>) -> Self

创建表定义构建器。

Source

pub fn label(self, label: impl Into<String>) -> Self

设置表展示名称。

Source

pub fn datasource(self, id: DatasourceId) -> Self

设置表所属逻辑数据源(默认 default)。

Source

pub fn primary_key_order(self, order: Vec<String>) -> Self

覆盖复合主键的列顺序(用于抵消字段排序)。

Source

pub fn fields<I>(self, fields: I) -> Self
where I: IntoIterator<Item = Field>,

批量添加字段;支持数组、Vec 和任意字段迭代器。

Source

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 等 无法安全映射为通用字段类型的列。

Source

pub fn unique<I, C>(self, fields: I) -> Self
where I: IntoIterator<Item = C>, C: Into<ColumnName>,

添加复合唯一索引。

Source

pub fn unique_named<I, C>(self, name: impl Into<String>, fields: I) -> Self
where I: IntoIterator<Item = C>, C: Into<ColumnName>,

添加指定名称的复合唯一索引。

Source

pub fn unique_nulls_not_distinct<I, C>(self, fields: I) -> Self
where I: IntoIterator<Item = C>, C: Into<ColumnName>,

添加复合唯一索引,并声明 PostgreSQL 15+ 的 NULLS NOT DISTINCT 语义。

空值互不异:两行该索引列均为 NULL 时会触发唯一冲突。仅 PostgreSQL 支持; MySQL 在 schema 同步时明确拒绝该标志。

Source

pub fn unique_named_nulls_not_distinct<I, C>( self, name: impl Into<String>, fields: I, ) -> Self
where I: IntoIterator<Item = C>, C: Into<ColumnName>,

添加指定名称的复合唯一索引,并声明 NULLS NOT DISTINCT 语义。

Source

pub fn index<I, C>(self, fields: I) -> Self
where I: IntoIterator<Item = C>, C: Into<ColumnName>,

添加复合普通索引。

Source

pub fn index_named<I, C>(self, name: impl Into<String>, fields: I) -> Self
where I: IntoIterator<Item = C>, C: Into<ColumnName>,

添加指定名称的复合普通索引。

Source

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
where I: IntoIterator<Item = C>, C: Into<ColumnName>, S: Into<String>,

添加带受信表达式键与/或部分索引谓词的索引(仅 PostgreSQL 支持)。

fields 与 expressions 至少一个非空;predicate 是 WHERE 后原样 渲染的受信 SQL 表达式。MySQL 在 schema 同步时明确拒绝部分/表达式索引。

Source

pub fn check_named( self, name: impl Into<String>, expression: impl Into<String>, ) -> Self

添加指定名称的 MySQL CHECK 约束。

表达式属于受信任的应用定义,不得来自请求或运行时配置。

Source

pub fn foreign_key_named<I, C, R, RC>( self, name: impl Into<String>, columns: I, referenced_table: impl Into<String>, referenced_columns: R, ) -> Self
where I: IntoIterator<Item = C>, C: Into<ColumnName>, R: IntoIterator<Item = RC>, RC: Into<ColumnName>,

添加指定名称的复合外键;更新和删除规则固定为 RESTRICT。

Source

pub fn default_order(self, order: Order) -> Self

设置首个默认排序规则。

Source

pub fn then_order(self, order: Order) -> Self

追加默认排序规则。

Source

pub fn build(self) -> Result<TableDefinition, BaseError>

校验并生成不可变表定义。

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Table

Source§

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

Formats the value using the given formatter. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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