3

How can I query from a JSON-type Column in PostgreSQL? Let's say following is my Entity witch contains the JSON-type column 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;
}

And I want to retrieve (SQL syntax) all Menus where validDates 's value is true (example of a validDates- entry: "Mon Aug 01 2018": true )

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
  • Does this answer your question? [typeorm postgres select where json field equals some value](https://stackoverflow.com/questions/52808304/typeorm-postgres-select-where-json-field-equals-some-value) – snakecharmerb Jul 15 '21 at 18:47

1 Answers1

0
async getAllBrands() {
  return this.productsRepository
    .query(`SELECT properties->'brand' as brand from product`);
}

For more details: https://wanago.io/2020/12/28/nestjs-json-postgresql-typeorm/

General Grievance
  • 4,555
  • 31
  • 31
  • 45