pub struct Resource { /* private fields */ }Expand description
A JSON:API resource type stored in one table, such as orders.
use fusion_stack::resources::{Kind, Resource};
let orders = Resource::new("orders", "orders")
.attribute("reference", Kind::String)
.attribute("total_cents", Kind::Integer)
.attribute("created_at", Kind::Timestamp)
.belongs_to("customer", "customers", "customer_id")
.describe("total_cents", "The order total in the smallest unit of the currency.");Implementations§
Source§impl Resource
impl Resource
Sourcepub fn new(kind: &str, table: &str) -> Self
pub fn new(kind: &str, table: &str) -> Self
A resource type, such as orders, whose records are rows of table, keyed by id.
Sourcepub fn attribute(self, name: &str, kind: Kind) -> Self
pub fn attribute(self, name: &str, kind: Kind) -> Self
An attribute read from the column of the same name. Attributes render in the order they are added.
Sourcepub fn attribute_from(self, name: &str, column: &str, kind: Kind) -> Self
pub fn attribute_from(self, name: &str, column: &str, kind: Kind) -> Self
An attribute read from a column with another name.
Sourcepub fn belongs_to(self, name: &str, related: &str, foreign_key: &str) -> Self
pub fn belongs_to(self, name: &str, related: &str, foreign_key: &str) -> Self
A to-one relationship: this table’s foreign_key column holds the related record’s key.
Sourcepub fn has_many(self, name: &str, related: &str, foreign_key: &str) -> Self
pub fn has_many(self, name: &str, related: &str, foreign_key: &str) -> Self
A to-many relationship: the related table’s foreign_key column holds this record’s key.
Related records are listed by key.
Sourcepub fn describe(self, field: &str, text: &str) -> Self
pub fn describe(self, field: &str, text: &str) -> Self
Describes an attribute or relationship in the OpenAPI document, as PHP’s #[Describe] does.
Sourcepub fn describe_values<I, V, D>(
self,
field: &str,
text: &str,
values: I,
) -> Self
pub fn describe_values<I, V, D>( self, field: &str, text: &str, values: I, ) -> Self
Describes an attribute with fixed values, and what each value means.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Resource
impl Freeze for Resourcewhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<Attribute>: Freeze,
PhantomData<Relationship>: Freeze,
PhantomData<(String, Description)>: Freeze,
impl Move for Resource
impl RefUnwindSafe for Resource
impl Send for Resourcewhere
RawVecInner: Send,
impl Sync for Resourcewhere
RawVecInner: Sync,
impl Unpin for Resource
impl UnsafeUnpin for Resourcewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<Attribute>: UnsafeUnpin,
PhantomData<Relationship>: UnsafeUnpin,
PhantomData<(String, Description)>: UnsafeUnpin,
impl UnwindSafe for Resourcewhere
RawVecInner: UnwindSafe,
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
Mutably borrows from an owned value. Read more