我们正在研究的内容:数据库实体

大家好!今天,我们在 Vast 开发了一项重要的新功能,该功能允许程序员在 Vast Studio 中创建和编辑数据库实体。

Database Entities in Vast Studio

Vast 已经支持 Schemas(类似于 NestJS DTO),实体也类似;它们有名称、描述、继承和属性。但实体还面临着额外的挑战:

  • 虽然架构属性可以是“可选的”,但实体属性始终是定义的,但可以为空
  • 实体需要特殊数据类型,例如主要生成的列
  • 与模式类似,实体可以引用其他实体(关系),但需要特殊的装饰器
  • 需要将实体添加到 TypeORM 模块注册中
  • 某些列类型应该从有效载荷中排除,例如生成的 ID 和关系
  • 实体列具有比 Typescript 类型更多的数据类型(例如数字可以是 int 或 float)
  • 当前状态

    Vast 的模式结构如下:

    export interface IProperty {
      name: string;
      typeSignature: PropertyType;
      isOptional: boolean;
      validators: Validator[];
    }
    
    export interface IClass

    extends OptionalTypeGraphNode { description: string | null; parentId: string; properties: P[]; } export interface ISchema extends IClass { inheritance: TypeRefPropertyType | null; }

    未来状态

    为了支持实体,我们需要创建一个扩展“IClass”的新接口:

    export interface IEntityProperty extends IProperty {}
    
    export interface IEntity extends IClass {
      properties: IEntityProperty[];
    }

    这使得我们可以定制实体的行为,但仍然从相同的基本接口扩展。

    以下是实体在 Vast Studio 中的样子以及它是如何生成为 NestJS 代码的。

    **Vast Studio 中的实体**

    Entity in Vast Studio

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

    有想法、建议或问题吗?请在下方告诉我们。或者免费下载 Vast Studio 并亲自试用:

    https://www.getvast.app/