DEV Community

James Harrison
James Harrison

Posted on

What we're working on: Database Entities

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.

Database Entities in 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:

  1. While schema properties can be "optional", entity properties are always defined but can be nullable
  2. Entities need special data types like primary generated columns
  3. Like schemas, Entities can reference other entities (relationships) but require special decorators
  4. Entities need to be added to the TypeORM module registration
  5. Certain column types should be excluded from payloads, like generated IDs and relationships
  6. Entity columns have more data types than Typescript types (e.g. number could be int or float)

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;
}

Enter fullscreen mode Exit fullscreen mode

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[];
}
Enter fullscreen mode Exit fullscreen mode

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 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;
}
Enter fullscreen mode Exit fullscreen mode

Have thoughts, suggestions or questions? Let us know below. Or download Vast Studio for free and try it for yourself:

https://www.getvast.app/

Google AI Education track image

Build Apps with Google AI Studio 🧱

This track will guide you through Google AI Studio's new "Build apps with Gemini" feature, where you can turn a simple text prompt into a fully functional, deployed web application in minutes.

Read more β†’

Top comments (0)

Scale globally with MongoDB Atlas. Try free.

Scale globally with MongoDB Atlas. Try free.

MongoDB Atlas is the global, multi-cloud database for modern apps trusted by developers and enterprises to build, scale, and run cutting-edge applications, with automated scaling, built-in security, and 125+ cloud regions.

Learn More

πŸ‘‹ Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's dayβ€”leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay