Entity
An entity is a basic object that represents a given schema.
Definition
- Library: tramway-core-connection
- File: https://github.com/tramwayjs/connection/blob/master/src/core/Entity.js
Create
tramway create:entity Product --properties width height price
Locations
- Implementation:
src/entities
API
Function | Usage |
---|---|
hasAttribute(attribute: string): boolean | Checks if attribute is in the Entity |
serialize(): string | Returns stringified JSON |
unserialize(item): Entity | Sets own attributes based on serialized string |
To create an entity, extend the class.
import { Entity } from 'tramway-core-connection';
Example
import { Entity } from 'tramway-core-connection';export default class Product extends Entity {getId() {return this.id;}setId(id) {this.id = id;return this;}getWidth() {return this.width;}setWidth(width) {this.width = width;return this;}getHeight() {return this.height;}setHeight(height) {this.height = height;return this;}getPrice() {return this.price;}setPrice(price) {this.price = price;return this;}}export const _frontmatter = {"title":"Entity","metaTitle":"Entity | TramwayJS","metaDescription":"An entity is a basic object that represents a given schema."}