Skip to main content

EntityTypeBuilder

Struct EntityTypeBuilder 

Source
pub struct EntityTypeBuilder<'a, T> { /* private fields */ }

Implementations§

Source§

impl<'a, T> EntityTypeBuilder<'a, T>

Source

pub fn new(model: &'a mut ModelBuilder, type_id: TypeId) -> Self

Source

pub fn to_table(&mut self, name: &str) -> &mut Self

Source

pub fn property_named<'b>( &'b mut self, field_name: &'static str, ) -> PropertyBuilder<'b, T>

Source

pub fn has_key_named(&mut self, field_name: &str) -> &mut Self

Source

pub fn has_keys(&mut self, field_names: &[&str]) -> &mut Self

Source

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".

Source

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).

Source

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.

Source

pub fn has_comment(&mut self, comment: &str) -> &mut Self

Sets the table/entity comment (HasComment).

Source

pub fn ignore(&mut self, field_name: &str) -> &mut Self

Ignores a scalar field (Ignore()), excluding it from mapping/DDL.

Source

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).

Source

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"));
Source

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).

Source

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],
);
Source

pub fn has_check(&mut self, name: &str, expression: &str) -> &mut Self

Declares a table-level CHECK constraint.

Source

pub fn engine(&mut self, name: &str) -> &mut Self

Sets the MySQL storage engine (e.g. InnoDB). Ignored on other dialects.

Source

pub fn charset(&mut self, name: &str) -> &mut Self

Sets the MySQL default character set (e.g. utf8mb4).

Source

pub fn collate(&mut self, name: &str) -> &mut Self

Sets the MySQL default collation (e.g. utf8mb4_bin).

Source

pub fn has_data(&mut self, data: &[T]) -> &mut Self
where T: IEntitySnapshot,

Seeds initial data (applied on DbContext::ensure_created).

Auto Trait Implementations§

§

impl<'a, T> !UnwindSafe for EntityTypeBuilder<'a, T>

§

impl<'a, T> Forget for EntityTypeBuilder<'a, T>

§

impl<'a, T> Freeze for EntityTypeBuilder<'a, T>
where PhantomData<T>: Freeze,

§

impl<'a, T> Move for EntityTypeBuilder<'a, T>

§

impl<'a, T> RefUnwindSafe for EntityTypeBuilder<'a, T>

§

impl<'a, T> Send for EntityTypeBuilder<'a, T>
where PhantomData<T>: Send,

§

impl<'a, T> Sync for EntityTypeBuilder<'a, T>
where PhantomData<T>: Sync,

§

impl<'a, T> Unpin for EntityTypeBuilder<'a, T>
where PhantomData<T>: Unpin,

§

impl<'a, T> UnsafeUnpin for EntityTypeBuilder<'a, T>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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