如何在NestJS中定义Postgres DB列顺序?

How to define Postgres DB column order in NestJS?

提问人:Chris Barr 提问时间:11/1/2023 更新时间:11/1/2023 访问量:21

问:

这是一个非常小的烦恼,但是在我的 NestJS 应用程序中,我有这个实体:

@Entity({ name: DB_TABLE_NAME_TEST })
export class TestEntity {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Exclude({ toPlainOnly: true }) //hide from response objects
  @ManyToOne(() => AccountEntity, (acct) => acct.id)
  @JoinColumn()
  account: string;

  @Column()
  description: string;

  @Column()
  testerName: string;

  @Column()
  testerEmail: string;

  @Column({ type: 'jsonb', array: false, default: () => "'[]'", nullable: false })
  @Type(() => Array<ITestEvent>)
  eventList: Array<ITestEvent>;

  @Column({ type: 'jsonb', array: false, default: () => "'[]'", nullable: false })
  @Type(() => Array<QuestionLibraryEntity>)
  questionLibraries: Array<QuestionLibraryEntity>;
}

当它为 PostgreSQL 创建表时,pgAdmin 中的列以不同的顺序显示

pgAdmin Column Order

这很烦人的唯一原因是因为我有 2 列,其中的数据可能很长,因此将列推离屏幕。我更愿意把它放在列旁边,就像我在 NestJS 实体中定义的那样。jsonbaccountIdid

有没有办法定义列顺序?

postgresql nestjs typeorm pgadmin

评论

0赞 Richard Huxton 11/1/2023
我在您的实体代码中根本没有看到“accountid”。其余列似乎与所描述的顺序匹配。
0赞 Chris Barr 11/2/2023
@RichardHuxton 它是 - typeORM 似乎添加了我可以使用的后缀。我相信它这样做是因为关系,因为这是一个外键,它添加了后缀以明确说明:typeorm.io/many-to-one-one-to-many-relationsaccountidManyToOne

答: 暂无答案