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 )

1

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.