Hey there! Today at Vast we're working on a big new feature that allows programmers to create and edit database entities within Vast Studio.
Vast already has support for Schemas (which are like NestJS DTOs), and Entities are similar; they have a name, description, inheritance and properties. But Entities come with additional challenges:
- While schema properties can be "optional", entity properties are always defined but can be nullable
- Entities need special data types like primary generated columns
- Like schemas, Entities can reference other entities (relationships) but require special decorators
- Entities need to be added to the TypeORM module registration
- Certain column types should be excluded from payloads, like generated IDs and relationships
- Entity columns have more data types than Typescript types (e.g.
number
could beint
orfloat
)
Current State
Vast's schemas are structured as follows:
export interface IProperty {
name: string;
typeSignature: PropertyType;
isOptional: boolean;
validators: Validator[];
}
export interface IClass<P extends IProperty = IProperty>
extends OptionalTypeGraphNode {
description: string | null;
parentId: string;
properties: P[];
}
export interface ISchema extends IClass {
inheritance: TypeRefPropertyType | null;
}
Future State
In order to support entities, we need to create a new interface that extends IClass
:
export interface IEntityProperty extends IProperty {}
export interface IEntity extends IClass<IEntityProperty> {
properties: IEntityProperty[];
}
This allows us to customize the behaviour of Entities but still extend from the same base interface.
Here's a look at how an Entity looks in Vast Studio and how it gets generated as NestJS code.
Entity in Vast Studio
Entity in NestJS
@Entity()
export class AddressEntity {
@PrimaryGeneratedColumn("uuid")
id: string;
@IsString()
@Column()
country: string;
@IsNumber({})
@Column({ nullable: true, type: "float" })
phone: number | null;
@IsString()
@Column()
state: string;
@IsString()
@Column()
street: string;
@IsString()
@Column()
suburb: string;
@ValidateNested()
@ManyToOne(() => UserEntity)
user: UserEntity;
}
Have thoughts, suggestions or questions? Let us know below. Or download Vast Studio for free and try it for yourself:
Top comments (0)