pub struct EntityTypeBuilder<'a, T> { /* private fields */ }Implementations§
Source§impl<'a, T> EntityTypeBuilder<'a, T>
impl<'a, T> EntityTypeBuilder<'a, T>
pub fn new(model: &'a mut ModelBuilder, type_id: TypeId) -> Self
pub fn to_table(&mut self, name: &str) -> &mut Self
pub fn property_named<'b>( &'b mut self, field_name: &'static str, ) -> PropertyBuilder<'b, T>
pub fn has_key_named(&mut self, field_name: &str) -> &mut Self
pub fn has_keys(&mut self, field_names: &[&str]) -> &mut Self
Sourcepub fn to_schema(&mut self, schema: &str) -> &mut Self
pub fn to_schema(&mut self, schema: &str) -> &mut Self
Qualifies the table with a schema/database prefix (ToTable(name, schema)).
Generates schema.table (quoted per part), e.g. PostgreSQL "audit"."logs".
Sourcepub fn to_view(&mut self, name: &str) -> &mut Self
pub fn to_view(&mut self, name: &str) -> &mut Self
Maps this entity to an existing database view (ToView).
View entities are excluded from table DDL (no CREATE/DROP/ALTER);
the view itself is managed outside rust-ef. The entity is read-only in
practice (save_changes should not be used for it).
Sourcepub fn has_no_key(&mut self) -> &mut Self
pub fn has_no_key(&mut self) -> &mut Self
Marks the entity as keyless (HasNoKey): no primary key is emitted.
Useful for projections/views. find/remove require a key and must not
be used on keyless entities.
Sourcepub fn has_comment(&mut self, comment: &str) -> &mut Self
pub fn has_comment(&mut self, comment: &str) -> &mut Self
Sets the table/entity comment (HasComment).
Sourcepub fn ignore(&mut self, field_name: &str) -> &mut Self
pub fn ignore(&mut self, field_name: &str) -> &mut Self
Ignores a scalar field (Ignore()), excluding it from mapping/DDL.
Sourcepub fn has_alternate_key(
&mut self,
columns: &'static [&'static str],
) -> &mut Self
pub fn has_alternate_key( &mut self, columns: &'static [&'static str], ) -> &mut Self
Declares an alternate key (HasAlternateKey): a unique constraint that
can be referenced by foreign keys.
Implemented as a unique index named ak_<table>_<cols> (equivalent for
PostgreSQL/SQLite/MySQL foreign-key targets).
Sourcepub fn has_index(
&mut self,
columns: &'static [&'static str],
) -> IndexBuilder<'_, T>
pub fn has_index( &mut self, columns: &'static [&'static str], ) -> IndexBuilder<'_, T>
Declares a (possibly composite) index from column constants.
Use linq!(index |b: T| (b.author_id, b.created_at)) to build the
column array type-safely. The returned IndexBuilder configures
uniqueness, an explicit name, or a partial-index predicate:
entity.has_index(&[Order::COLUMN_TENANT_ID, Order::COLUMN_REQUEST_KEY])
.is_unique();
entity.has_index(&[Invite::COLUMN_TENANT_ID, Invite::COLUMN_CODE])
.is_unique()
.has_filter(linq!(|i: Invite| i.status == "PENDING"));Sourcepub fn has_index_expression(
&mut self,
expressions: &'static [&'static str],
) -> IndexBuilder<'_, T>
pub fn has_index_expression( &mut self, expressions: &'static [&'static str], ) -> IndexBuilder<'_, T>
Declares an index over raw SQL expressions, e.g.
has_index_expression(&["coalesce(channel_id, '')"]).
Expressions are emitted verbatim, so write portable SQL (lower-case identifiers work unquoted on PostgreSQL, SQLite and MySQL).
Sourcepub fn has_foreign_key(
&mut self,
columns: &'static [&'static str],
referenced_table: &'static str,
referenced_columns: &'static [&'static str],
) -> ForeignKeyBuilder<'_, T>
pub fn has_foreign_key( &mut self, columns: &'static [&'static str], referenced_table: &'static str, referenced_columns: &'static [&'static str], ) -> ForeignKeyBuilder<'_, T>
Declares a (possibly composite) foreign key.
Single-column keys are usually inferred from BelongsTo navigations or
#[foreign_key(Target)]; use this for composite keys such as
(tenant_id, order_id) → order_record(tenant_id, id):
entity.has_foreign_key(
&[Voucher::COLUMN_TENANT_ID, Voucher::COLUMN_ORDER_ID],
OrderRecord::TABLE,
&[OrderRecord::COLUMN_TENANT_ID, OrderRecord::COLUMN_ID],
);Sourcepub fn has_check(&mut self, name: &str, expression: &str) -> &mut Self
pub fn has_check(&mut self, name: &str, expression: &str) -> &mut Self
Declares a table-level CHECK constraint.
Sourcepub fn engine(&mut self, name: &str) -> &mut Self
pub fn engine(&mut self, name: &str) -> &mut Self
Sets the MySQL storage engine (e.g. InnoDB). Ignored on other dialects.
Sourcepub fn charset(&mut self, name: &str) -> &mut Self
pub fn charset(&mut self, name: &str) -> &mut Self
Sets the MySQL default character set (e.g. utf8mb4).
Sourcepub fn collate(&mut self, name: &str) -> &mut Self
pub fn collate(&mut self, name: &str) -> &mut Self
Sets the MySQL default collation (e.g. utf8mb4_bin).
Sourcepub fn has_data(&mut self, data: &[T]) -> &mut Selfwhere
T: IEntitySnapshot,
pub fn has_data(&mut self, data: &[T]) -> &mut Selfwhere
T: IEntitySnapshot,
Seeds initial data (applied on DbContext::ensure_created).