Skip to main content

ModelMeta

Struct ModelMeta 

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

What #[derive(Model)] knows about a model: its name, table, key, columns, timestamps, soft-delete column, connection and page size.

Built with const methods, so the derive writes it as a static.

use navree_orm::{ColumnMeta, KeyKind, ModelMeta};

static COLUMNS: [ColumnMeta; 2] = [
    ColumnMeta::new("id", "id", "i64"),
    ColumnMeta::new("title", "title", "String"),
];
static META: ModelMeta = ModelMeta::new("Deal", "deals")
    .primary_key("id", KeyKind::Increments)
    .columns(&COLUMNS)
    .per_page(25);
assert_eq!(META.table(), "deals");
assert_eq!(META.column("title").unwrap().rust_type(), "String");
assert!(!META.uses_timestamps());

Implementations§

Source§

impl ModelMeta

Source

pub const fn new(name: &'static str, table: &'static str) -> Self

Model name stored in table, keyed by an auto-incrementing id, 15 records per page, totally guarded (no column is fillable), with nothing hidden and nothing appended.

Source

pub const fn fillable(self, columns: &'static [&'static str]) -> Self

The columns fill may set (#[model(fillable(..))]); JSON paths into a JSON column are written "meta->status".

Source

pub const fn guarded(self, columns: &'static [&'static str]) -> Self

The columns fill may not set (#[model(guarded(..))]); every other column becomes fillable. An empty list guards nothing.

Source

pub const fn unguarded(self) -> Self

Mass assignment is never guarded for this model (#[model(unguarded)]).

Source

pub const fn hidden(self, names: &'static [&'static str]) -> Self

The names left out of serialized records (#[model(hidden(..))] and fields marked #[model(hidden)]).

Source

pub const fn visible(self, names: &'static [&'static str]) -> Self

The only names serialized records keep (#[model(visible(..))]); empty keeps every name.

Source

pub const fn appends(self, names: &'static [&'static str]) -> Self

The accessors appended to serialized records (#[model(appends(..))]).

Source

pub const fn encrypter(self, name: &'static str) -> Self

The named Encrypter the model’s encrypted casts use (#[model(encrypter = "...")]).

Source

pub const fn factory( self, name: &'static str, relationships: fn() -> Vec<RelationshipInfo>, ) -> Self

The model’s factory, as written in #[model(factory = ...)], and the relationships it declares (model:show lists both).

Source

pub const fn subject(self, subject: &'static str) -> Self

The navree-access subject the model’s records are (#[model(subject)]).

Source

pub const fn policy(self, policy: &'static str) -> Self

The policy attached to the model, as written in #[model(policy = ...)].

Source

pub const fn factory_name(&self) -> Option<&'static str>

The model’s factory, as written in #[model(factory = ...)].

Source

pub fn factory_relationships(&self) -> Vec<RelationshipInfo>

The relationships the model’s factory declares (ModelFactory::relationships), in declaration order; none without a factory.

Source

pub const fn subject_name(&self) -> Option<&'static str>

The navree-access subject of the model’s records, if it is one.

Source

pub const fn policy_name(&self) -> Option<&'static str>

The policy attached to the model, as written.

Source

pub const fn route_key(self, column: &'static str) -> Self

The column route model binding looks records up by, when it is not the key (#[model(route_key = "slug")]).

Source

pub const fn workspace(self, column: &'static str) -> Self

The column holding a workspace-scoped model’s workspace (#[model(workspace)]): queries see the current workspace’s records only, and new records get it.

Source

pub const fn cast_context(self, needed: bool) -> Self

Whether a cast of the model needs a CastContext (resolved from the app before records are read or written).

Source

pub const fn serialize_dates_with(self, serializer: DateSerializer) -> Self

How serialized records write the model’s date-times (#[model(serialize_dates_with = path)]).

Source

pub const fn morph_name(self, name: &'static str) -> Self

The name polymorphic type columns store for the model (#[model(morph_name = "...")]; the derive writes the snake_case type name when none is given).

Source

pub const fn foreign_key(self, column: &'static str) -> Self

The column other models’ foreign keys to this model are named by default (company_id).

Source

pub const fn touches(self, relations: &'static [&'static str]) -> Self

The relations whose records are touched (their update timestamp set to now) when a record of this model is saved or deleted (#[model(touches = ["company"])]).

Source

pub const fn with(self, relations: &'static [&'static str]) -> Self

The relations every query of the model eager loads (#[model(with = ["company"])]).

Source

pub const fn with_count(self, relations: &'static [&'static str]) -> Self

The relations every query of the model counts (#[model(with_count = ["notes"])]).

Source

pub const fn pivot_keys( self, foreign_key: &'static str, related_key: &'static str, ) -> Self

For a pivot model without an id column: the pivot columns pointing at the two related records. Its rows are identified by both (#[model(pivot(foreign_key = "deal_id", related_key = "tag_id"))]).

Source

pub const fn pruned(self, pruning: Pruning) -> Self

How model:prune prunes the model (#[model(prunable)], #[model(mass_prunable)]).

Source

pub const fn pruning(&self) -> Option<&Pruning>

How the model is pruned, when it is prunable.

Source

pub const fn primary_key(self, column: &'static str, kind: KeyKind) -> Self

The key column and how it gets its value.

Source

pub const fn columns(self, columns: &'static [ColumnMeta]) -> Self

The columns, in field order.

Source

pub const fn timestamps( self, created_at: Option<&'static str>, updated_at: Option<&'static str>, ) -> Self

The creation and update timestamp columns (either may be None).

Source

pub const fn soft_deletes(self, column: &'static str) -> Self

The soft-delete column: deleting sets it, queries skip rows where it is set.

Source

pub const fn connection(self, name: &'static str) -> Self

The named connection the model lives on.

Source

pub const fn driver(self, name: &'static str) -> Self

The document driver the model is stored with (mongodb), declared with #[model(driver = "...")]; SQL models declare none.

Source

pub const fn per_page(self, per_page: u64) -> Self

The default page size.

Source

pub const fn name(&self) -> &'static str

The model’s name, e.g. Deal.

Source

pub const fn table(&self) -> &'static str

The table.

Source

pub const fn key_column(&self) -> &'static str

The key column.

Source

pub const fn key_kind(&self) -> KeyKind

How the key gets its value.

Source

pub const fn all_columns(&self) -> &'static [ColumnMeta]

Every column, in field order.

Source

pub fn column(&self, name: &str) -> Option<&'static ColumnMeta>

The column name, if the model has it.

Source

pub fn has_column(&self, name: &str) -> bool

Whether the model has column name.

Source

pub const fn created_at(&self) -> Option<&'static str>

The creation timestamp column.

Source

pub const fn updated_at(&self) -> Option<&'static str>

The update timestamp column.

Source

pub const fn uses_timestamps(&self) -> bool

Whether the model keeps either timestamp.

Source

pub const fn deleted_at(&self) -> Option<&'static str>

The soft-delete column.

Source

pub const fn soft_deletes_enabled(&self) -> bool

Whether the model soft-deletes.

Source

pub const fn connection_name(&self) -> Option<&'static str>

The named connection, if the model declares one.

Source

pub const fn driver_name(&self) -> Option<&'static str>

The document driver the model declares (#[model(driver = "mongodb")]); None for SQL models.

Source

pub const fn default_per_page(&self) -> u64

The default page size.

Source

pub fn morph_type(&self) -> Cow<'static, str>

The name polymorphic type columns store for the model: the declared one, else the snake_case model name (DealStage → deal_stage).

Source

pub fn foreign_key_name(&self) -> Cow<'static, str>

The default name of foreign keys to the model: the declared one, else the snake_case model name, _, and the key column (Company keyed by id → company_id).

Source

pub const fn touched_relations(&self) -> &'static [&'static str]

The relations touched when a record is saved or deleted.

Source

pub const fn default_with(&self) -> &'static [&'static str]

The relations every query eager loads.

Source

pub const fn default_with_count(&self) -> &'static [&'static str]

The relations every query counts.

Source

pub const fn pivot_key_columns(&self) -> Option<(&'static str, &'static str)>

The two pivot columns of a pivot model (#[model(pivot(..))]): (foreign_key, related_key). A pivot model without an id column is keyed by related_key, and its rows are identified by both.

Source

pub const fn fillable_columns(&self) -> &'static [&'static str]

The fillable columns, as declared.

Source

pub const fn guarded_columns(&self) -> Option<&'static [&'static str]>

The guarded columns, as declared: None when the model declares no guarded list (then every column is guarded unless it is fillable).

Source

pub const fn is_unguarded(&self) -> bool

Whether the model is never guarded (#[model(unguarded)]).

Source

pub const fn hidden_names(&self) -> &'static [&'static str]

The names hidden in serialized records.

Source

pub const fn visible_names(&self) -> &'static [&'static str]

The only names serialized records keep; empty keeps every name.

Source

pub const fn appended_names(&self) -> &'static [&'static str]

The accessors appended to serialized records.

Source

pub const fn encrypter_name(&self) -> Option<&'static str>

The named Encrypter the model’s encrypted casts use, if it names one.

Source

pub const fn uses_cast_context(&self) -> bool

Whether a cast of the model needs a cast context.

Source

pub const fn date_serializer(&self) -> Option<DateSerializer>

How serialized records write the model’s date-times, when the model overrides the default (RFC 3339, UTC, microseconds).

Source

pub fn column_of_field(&self, field: &str) -> Option<&'static ColumnMeta>

The column whose field is field (its first column, for a field stored across several columns).

Source

pub fn column_named(&self, name: &str) -> Option<&'static ColumnMeta>

The column called name, or the column of the field called name.

Source

pub const fn route_key_column(&self) -> &'static str

The column route model binding looks records up by: the declared route key, else the key column.

Source

pub const fn workspace_column(&self) -> Option<&'static str>

The workspace column of a workspace-scoped model.

Source

pub const fn is_workspace_scoped(&self) -> bool

Whether the model is scoped to workspaces.

Trait Implementations§

Source§

impl Debug for ModelMeta

Source§

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

Formats the value using the given formatter. Read more

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
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<T> ValueFor<Option<T>> for T

Source§

fn into_value_for(self) -> Option<T>

The value as the column’s type.
Source§

impl<T> ValueFor<T> for T

Source§

fn into_value_for(self) -> T

The value as the column’s type.
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