pub struct Field { /* private fields */ }Expand description
Schema-first 字段构建器。
字段名和字段配置从构造函数开始就是一个整体,例如
Field::string("username", 64).required().unique()。
Implementations§
Source§impl Field
impl Field
Sourcepub fn enumeration<I, S>(name: impl Into<String>, values: I) -> Self
pub fn enumeration<I, S>(name: impl Into<String>, values: I) -> Self
创建枚举字段。
Sourcepub fn created_at(name: impl Into<String>) -> Self
pub fn created_at(name: impl Into<String>) -> Self
创建自动写入的创建时间字段。
Sourcepub fn updated_at(name: impl Into<String>) -> Self
pub fn updated_at(name: impl Into<String>) -> Self
创建自动写入的更新时间字段。
Sourcepub fn soft_delete(name: impl Into<String>) -> Self
pub fn soft_delete(name: impl Into<String>) -> Self
创建软删除时间字段。
Sourcepub fn auto_increment(self) -> Self
pub fn auto_increment(self) -> Self
设置数据库自增。
Sourcepub fn primary_key(self) -> Self
pub fn primary_key(self) -> Self
设置为主键。
Sourcepub fn unique_named(self, name: impl Into<String>) -> Self
pub fn unique_named(self, name: impl Into<String>) -> Self
添加指定名称的单字段唯一索引。
Sourcepub fn index_named(self, name: impl Into<String>) -> Self
pub fn index_named(self, name: impl Into<String>) -> Self
添加指定名称的单字段普通索引。
Sourcepub fn min_length(self, value: usize) -> Self
pub fn min_length(self, value: usize) -> Self
设置字符串最小长度。
Sourcepub fn max_length(self, value: usize) -> Self
pub fn max_length(self, value: usize) -> Self
设置字符串最大长度验证。
Sourcepub fn length(self, range: RangeInclusive<usize>) -> Self
pub fn length(self, range: RangeInclusive<usize>) -> Self
同时设置字符串最小、最大长度验证。
Sourcepub fn not_readable(self) -> Self
pub fn not_readable(self) -> Self
禁止任何角色读取。
Sourcepub fn readable_by<I, S>(self, roles: I) -> Self
pub fn readable_by<I, S>(self, roles: I) -> Self
仅允许指定角色读取。
Sourcepub fn writable_by<I, S>(self, roles: I) -> Self
pub fn writable_by<I, S>(self, roles: I) -> Self
仅允许指定角色写入。
Sourcepub fn not_writable(self) -> Self
pub fn not_writable(self) -> Self
禁止任何角色写入。
Sourcepub fn searchable(self) -> Self
pub fn searchable(self) -> Self
允许字段用于关键词搜索(OR LIKE)。
与结构化筛选的 Field::filterable 位相互独立;只有文本字段
(Field::string / Field::text)会实际参与搜索,定义层在构建期
会对非文本字段的 searchable 声明报错。
Sourcepub fn filterable(self) -> Self
pub fn filterable(self) -> Self
允许字段用于筛选。
Sourcepub fn not_filterable(self) -> Self
pub fn not_filterable(self) -> Self
禁止字段用于筛选。
Sourcepub fn filterable_by<I, S>(self, roles: I) -> Self
pub fn filterable_by<I, S>(self, roles: I) -> Self
仅允许指定角色使用字段筛选。
Sourcepub fn not_sortable(self) -> Self
pub fn not_sortable(self) -> Self
禁止字段用于排序。
Sourcepub fn sortable_by<I, S>(self, roles: I) -> Self
pub fn sortable_by<I, S>(self, roles: I) -> Self
仅允许指定角色使用字段排序。
Sourcepub fn tenant_key(self) -> Self
pub fn tenant_key(self) -> Self
将字段标记为租户隔离键。
Sourcepub fn secret(self) -> Self
pub fn secret(self) -> Self
设置敏感字段预设。
敏感字段不会进入默认 Record 投影或表 JSON Schema,并默认禁止读取、写入、
筛选和排序。内部服务若确实需要显式读取或写入,必须随后调用
Field::readable_by / Field::writable_by 指定专用角色和显式字段列表。
Sourcepub fn relation(
self,
table: impl Into<String>,
field: impl Into<String>,
relation_type: RelationType,
) -> Self
pub fn relation( self, table: impl Into<String>, field: impl Into<String>, relation_type: RelationType, ) -> Self
设置关联关系。
Sourcepub fn relation_display_fields<I, S>(self, fields: I) -> Self
pub fn relation_display_fields<I, S>(self, fields: I) -> Self
设置关联展示字段。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Field
impl !UnwindSafe for Field
impl Freeze for Field
impl Send for Field
impl Sync for Field
impl Unpin for Field
impl UnsafeUnpin for Field
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