pub struct Resource {
pub meta: ResourceMeta,
pub fields: BTreeMap<String, Field>,
pub permissions: Permissions,
pub hooks: Hooks,
pub auth: Option<AuthSpec>,
pub admin: ResourceAdmin,
}Expand description
A fully-parsed resource definition.
Fields§
§meta: ResourceMeta§fields: BTreeMap<String, Field>Ordered map so generated columns/endpoints are deterministic.
permissions: Permissions§hooks: HooksNamed functions to run around each CRUD operation.
auth: Option<AuthSpec>Optional auth configuration; only meaningful on the user resource.
admin: ResourceAdminHow (and whether) this resource appears in the generated admin dashboard.
Implementations§
Source§impl Resource
impl Resource
Sourcepub fn table_name(&self) -> String
pub fn table_name(&self) -> String
Physical table name.
Sourcepub fn hook(&self, event: HookEvent) -> Option<&str>
pub fn hook(&self, event: HookEvent) -> Option<&str>
The function bound to a lifecycle event, if any.
Sourcepub fn auth_hook(&self, event: AuthEvent) -> Option<&str>
pub fn auth_hook(&self, event: AuthEvent) -> Option<&str>
The function bound to an auth event, if any. Only meaningful on the
user resource, which owns the built-in auth endpoints.
Sourcepub fn admin_label(&self) -> String
pub fn admin_label(&self) -> String
Human label for a single record, e.g. "Purchase order".
Sourcepub fn admin_plural(&self) -> String
pub fn admin_plural(&self) -> String
Human label for the collection, e.g. "Purchase orders".
Sourcepub fn admin_display_field(&self) -> Option<String>
pub fn admin_display_field(&self) -> Option<String>
The field whose value names a record in tables, pickers and headings.
An explicit display_field wins; otherwise the first conventionally
named field (name, title, …), then the first plain string field, and
finally None — at which point the dashboard falls back to the id.
Sourcepub fn admin_search_field(&self) -> Option<String>
pub fn admin_search_field(&self) -> Option<String>
The field the dashboard’s list search box filters on.
Always a string or text column, because searching means matching
part of a value: a display_field of another type names records
perfectly well and simply leaves the resource without a search box.
Sourcepub fn admin_columns(&self) -> Vec<String>
pub fn admin_columns(&self) -> Vec<String>
The columns the list table shows, in order.
Declared columns win. Otherwise: the display field first, then up to
four more dashboard-visible fields, skipping json/text blobs (which
never read well in a cell) and the tenancy column.
Sourcepub fn references(&self) -> Vec<Reference>
pub fn references(&self) -> Vec<Reference>
All belongs_to references declared by this resource’s fields.
Sourcepub fn reference_by_relation(&self, relation: &str) -> Option<Reference>
pub fn reference_by_relation(&self, relation: &str) -> Option<Reference>
Find the reference exposed under a given relation name ("owner").
Sourcepub fn is_org_scoped(&self) -> bool
pub fn is_org_scoped(&self) -> bool
Whether this resource is isolated per organisation (the default).
Sourcepub fn org_column(&self) -> Option<&'static str>
pub fn org_column(&self) -> Option<&'static str>
The column that carries this resource’s organisation, if any:
organization_id for org-scoped resources, id for the organization
resource itself (its rows are organisations), else None.