Skip to main content

TableSpec

Struct TableSpec 

Source
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

Source

pub fn new(name: TableName) -> Self

创建空表定义。

Source

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

设置表标题。

Source

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

设置表所属逻辑数据源。

Source

pub fn fields(self, fields: Fields) -> Self

使用 Fields 作为唯一字段来源。

Source

pub fn field(self, field: FieldSpec) -> Self

增加一个已经命名的字段定义。

Source

pub fn unique(self, fields: impl IntoIterator<Item = FieldRef>) -> Self

添加复合唯一索引。

Source

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

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

Source

pub fn index(self, fields: impl IntoIterator<Item = FieldRef>) -> Self

添加复合普通索引。

Source

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

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

Source

pub fn partial_index( self, name: impl Into<String>, fields: impl IntoIterator<Item = FieldRef>, predicate: impl Into<String>, ) -> Self

添加带 WHERE 谓词的 PostgreSQL 部分索引。

Source

pub fn partial_unique_named( self, name: impl Into<String>, fields: impl IntoIterator<Item = FieldRef>, predicate: impl Into<String>, ) -> Self

添加带 WHERE 谓词的 PostgreSQL 部分唯一索引。

Source

pub fn expression_index( self, name: impl Into<String>, expressions: impl IntoIterator<Item = impl Into<String>>, unique: bool, ) -> Self

添加表达式索引(如 lower(email))。

Source

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

添加指定名称的 CHECK 约束。

Source

pub fn foreign_key_named( self, name: impl Into<String>, fields: impl IntoIterator<Item = FieldRef>, referenced_fields: impl IntoIterator<Item = FieldRef>, ) -> Self

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

Source

pub fn opaque_column( self, name: impl Into<String>, sql_type: impl Into<String>, ) -> Self

声明一个框架不建模的存量列(仅 PostgreSQL)。

Source

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

生成 schema 同步和 TableQuery 使用的不可变执行产物。

Trait Implementations§

Source§

impl Clone for TableSpec

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 TableSpec

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for TableSpec

Source§

impl PartialEq for TableSpec

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TableSpec

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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