Defining a new database entity

Defining a new database entity

This example shows how new TypeORM database entities can be defined by plugins.

// product-review.entity.ts
import { DeepPartial } from '@vendure/common/lib/shared-types';
import { VendureEntity } from '@vendure/core';
import { Column, Entity } from 'typeorm';

class ProductReview extends VendureEntity {
  constructor(input?: DeepPartial<ProductReview>) {

  text: string;
  rating: number;

Note Any custom entities must extend the VendureEntity class.

The new entity is then passed to the entities array of the VendurePlugin metadata:

// reviews-plugin.ts
import { VendurePlugin } from '@vendure/core';
import { ProductReview } from './product-review.entity';

  entities: [ProductReview],
export class ReviewsPlugin {}