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
impl ModelMeta
Sourcepub const fn new(name: &'static str, table: &'static str) -> Self
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.
Sourcepub const fn fillable(self, columns: &'static [&'static str]) -> Self
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".
Sourcepub const fn guarded(self, columns: &'static [&'static str]) -> Self
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.
Sourcepub const fn unguarded(self) -> Self
pub const fn unguarded(self) -> Self
Mass assignment is never guarded for this model
(#[model(unguarded)]).
The names left out of serialized records (#[model(hidden(..))] and
fields marked #[model(hidden)]).
Sourcepub const fn visible(self, names: &'static [&'static str]) -> Self
pub const fn visible(self, names: &'static [&'static str]) -> Self
The only names serialized records keep (#[model(visible(..))]);
empty keeps every name.
Sourcepub const fn appends(self, names: &'static [&'static str]) -> Self
pub const fn appends(self, names: &'static [&'static str]) -> Self
The accessors appended to serialized records
(#[model(appends(..))]).
Sourcepub const fn encrypter(self, name: &'static str) -> Self
pub const fn encrypter(self, name: &'static str) -> Self
The named Encrypter the model’s encrypted casts use
(#[model(encrypter = "...")]).
Sourcepub const fn factory(
self,
name: &'static str,
relationships: fn() -> Vec<RelationshipInfo>,
) -> Self
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).
Sourcepub const fn subject(self, subject: &'static str) -> Self
pub const fn subject(self, subject: &'static str) -> Self
The navree-access subject the model’s records are
(#[model(subject)]).
Sourcepub const fn policy(self, policy: &'static str) -> Self
pub const fn policy(self, policy: &'static str) -> Self
The policy attached to the model, as written in
#[model(policy = ...)].
Sourcepub const fn factory_name(&self) -> Option<&'static str>
pub const fn factory_name(&self) -> Option<&'static str>
The model’s factory, as written in #[model(factory = ...)].
Sourcepub fn factory_relationships(&self) -> Vec<RelationshipInfo>
pub fn factory_relationships(&self) -> Vec<RelationshipInfo>
The relationships the model’s factory declares
(ModelFactory::relationships),
in declaration order; none without a factory.
Sourcepub const fn subject_name(&self) -> Option<&'static str>
pub const fn subject_name(&self) -> Option<&'static str>
The navree-access subject of the model’s records, if it is one.
Sourcepub const fn policy_name(&self) -> Option<&'static str>
pub const fn policy_name(&self) -> Option<&'static str>
The policy attached to the model, as written.
Sourcepub const fn route_key(self, column: &'static str) -> Self
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")]).
Sourcepub const fn workspace(self, column: &'static str) -> Self
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.
Sourcepub const fn cast_context(self, needed: bool) -> Self
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).
Sourcepub const fn serialize_dates_with(self, serializer: DateSerializer) -> Self
pub const fn serialize_dates_with(self, serializer: DateSerializer) -> Self
How serialized records write the model’s date-times
(#[model(serialize_dates_with = path)]).
Sourcepub const fn morph_name(self, name: &'static str) -> Self
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).
Sourcepub const fn foreign_key(self, column: &'static str) -> Self
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).
Sourcepub const fn touches(self, relations: &'static [&'static str]) -> Self
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"])]).
Sourcepub const fn with(self, relations: &'static [&'static str]) -> Self
pub const fn with(self, relations: &'static [&'static str]) -> Self
The relations every query of the model eager loads
(#[model(with = ["company"])]).
Sourcepub const fn with_count(self, relations: &'static [&'static str]) -> Self
pub const fn with_count(self, relations: &'static [&'static str]) -> Self
The relations every query of the model counts
(#[model(with_count = ["notes"])]).
Sourcepub const fn pivot_keys(
self,
foreign_key: &'static str,
related_key: &'static str,
) -> Self
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"))]).
Sourcepub const fn pruned(self, pruning: Pruning) -> Self
pub const fn pruned(self, pruning: Pruning) -> Self
How model:prune prunes the model (#[model(prunable)],
#[model(mass_prunable)]).
Sourcepub const fn primary_key(self, column: &'static str, kind: KeyKind) -> Self
pub const fn primary_key(self, column: &'static str, kind: KeyKind) -> Self
The key column and how it gets its value.
Sourcepub const fn columns(self, columns: &'static [ColumnMeta]) -> Self
pub const fn columns(self, columns: &'static [ColumnMeta]) -> Self
The columns, in field order.
Sourcepub const fn timestamps(
self,
created_at: Option<&'static str>,
updated_at: Option<&'static str>,
) -> Self
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).
Sourcepub const fn soft_deletes(self, column: &'static str) -> Self
pub const fn soft_deletes(self, column: &'static str) -> Self
The soft-delete column: deleting sets it, queries skip rows where it is set.
Sourcepub const fn connection(self, name: &'static str) -> Self
pub const fn connection(self, name: &'static str) -> Self
The named connection the model lives on.
Sourcepub const fn driver(self, name: &'static str) -> Self
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.
Sourcepub const fn key_column(&self) -> &'static str
pub const fn key_column(&self) -> &'static str
The key column.
Sourcepub const fn all_columns(&self) -> &'static [ColumnMeta]
pub const fn all_columns(&self) -> &'static [ColumnMeta]
Every column, in field order.
Sourcepub fn column(&self, name: &str) -> Option<&'static ColumnMeta>
pub fn column(&self, name: &str) -> Option<&'static ColumnMeta>
The column name, if the model has it.
Sourcepub fn has_column(&self, name: &str) -> bool
pub fn has_column(&self, name: &str) -> bool
Whether the model has column name.
Sourcepub const fn created_at(&self) -> Option<&'static str>
pub const fn created_at(&self) -> Option<&'static str>
The creation timestamp column.
Sourcepub const fn updated_at(&self) -> Option<&'static str>
pub const fn updated_at(&self) -> Option<&'static str>
The update timestamp column.
Sourcepub const fn uses_timestamps(&self) -> bool
pub const fn uses_timestamps(&self) -> bool
Whether the model keeps either timestamp.
Sourcepub const fn deleted_at(&self) -> Option<&'static str>
pub const fn deleted_at(&self) -> Option<&'static str>
The soft-delete column.
Sourcepub const fn soft_deletes_enabled(&self) -> bool
pub const fn soft_deletes_enabled(&self) -> bool
Whether the model soft-deletes.
Sourcepub const fn connection_name(&self) -> Option<&'static str>
pub const fn connection_name(&self) -> Option<&'static str>
The named connection, if the model declares one.
Sourcepub const fn driver_name(&self) -> Option<&'static str>
pub const fn driver_name(&self) -> Option<&'static str>
The document driver the model declares (#[model(driver = "mongodb")]); None for SQL models.
Sourcepub const fn default_per_page(&self) -> u64
pub const fn default_per_page(&self) -> u64
The default page size.
Sourcepub fn morph_type(&self) -> Cow<'static, str>
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).
Sourcepub fn foreign_key_name(&self) -> Cow<'static, str>
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).
Sourcepub const fn touched_relations(&self) -> &'static [&'static str]
pub const fn touched_relations(&self) -> &'static [&'static str]
The relations touched when a record is saved or deleted.
Sourcepub const fn default_with(&self) -> &'static [&'static str]
pub const fn default_with(&self) -> &'static [&'static str]
The relations every query eager loads.
Sourcepub const fn default_with_count(&self) -> &'static [&'static str]
pub const fn default_with_count(&self) -> &'static [&'static str]
The relations every query counts.
Sourcepub const fn pivot_key_columns(&self) -> Option<(&'static str, &'static str)>
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.
Sourcepub const fn fillable_columns(&self) -> &'static [&'static str]
pub const fn fillable_columns(&self) -> &'static [&'static str]
The fillable columns, as declared.
Sourcepub const fn guarded_columns(&self) -> Option<&'static [&'static str]>
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).
Sourcepub const fn is_unguarded(&self) -> bool
pub const fn is_unguarded(&self) -> bool
Whether the model is never guarded (#[model(unguarded)]).
The names hidden in serialized records.
Sourcepub const fn visible_names(&self) -> &'static [&'static str]
pub const fn visible_names(&self) -> &'static [&'static str]
The only names serialized records keep; empty keeps every name.
Sourcepub const fn appended_names(&self) -> &'static [&'static str]
pub const fn appended_names(&self) -> &'static [&'static str]
The accessors appended to serialized records.
Sourcepub const fn encrypter_name(&self) -> Option<&'static str>
pub const fn encrypter_name(&self) -> Option<&'static str>
The named Encrypter the model’s encrypted casts use, if it names
one.
Sourcepub const fn uses_cast_context(&self) -> bool
pub const fn uses_cast_context(&self) -> bool
Whether a cast of the model needs a cast context.
Sourcepub const fn date_serializer(&self) -> Option<DateSerializer>
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).
Sourcepub fn column_of_field(&self, field: &str) -> Option<&'static ColumnMeta>
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).
Sourcepub fn column_named(&self, name: &str) -> Option<&'static ColumnMeta>
pub fn column_named(&self, name: &str) -> Option<&'static ColumnMeta>
The column called name, or the column of the field called name.
Sourcepub const fn route_key_column(&self) -> &'static str
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.
Sourcepub const fn workspace_column(&self) -> Option<&'static str>
pub const fn workspace_column(&self) -> Option<&'static str>
The workspace column of a workspace-scoped model.
Sourcepub const fn is_workspace_scoped(&self) -> bool
pub const fn is_workspace_scoped(&self) -> bool
Whether the model is scoped to workspaces.
Trait Implementations§
Auto Trait Implementations§
impl Forget for ModelMeta
impl Freeze for ModelMeta
impl Move for ModelMeta
impl RefUnwindSafe for ModelMeta
impl Send for ModelMeta
impl Sync for ModelMeta
impl Unpin for ModelMeta
impl UnsafeUnpin for ModelMeta
impl UnwindSafe for ModelMeta
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
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> ⓘ
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> ⓘ
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