【问题标题】:How to make a query with PostgreSQL and TypeORM) where a Table has a JSON Type Column如何使用 PostgreSQL 和 TypeORM 进行查询)其中表具有 JSON 类型列
【发布时间】:2019-01-09 14:13:59
【问题描述】:

如何从 PostgreSQL 中的 JSON 类型的列进行查询?假设以下是我的实体女巫,其中包含 JSON 类型的列 validDates:

// My Menu - Entity Class
@Entity()
export Class Menu {
  @PrimaryGeneratedColumn('uuid')
     id: string;
  @Column('json', {nullable: true})
    validDates?: ValidDatesClass;
}

// The ValidDatesClass
export class ValidDatesClass {
   [key: string]: boolean;
}

我想检索(SQL 语法)validDates 的值为 true 的所有菜单(validDates- 条目示例:“Mon Aug 01 2018”:true)

【问题讨论】:

标签: postgresql nestjs typeorm


【解决方案1】:
async getAllBrands() {
  return this.productsRepository
    .query(`SELECT properties->'brand' as brand from product`);
}

更多详情: https://wanago.io/2020/12/28/nestjs-json-postgresql-typeorm/

【讨论】:

    猜你喜欢
    • 2012-05-20
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 2018-05-28
    相关资源
    最近更新 更多