Skip to main content

Function: ViewEntity()

ViewEntity(viewName): ClassDecorator

Defined in: src/decorators/Table.ts:95

Class decorator mapping an entity class to a database VIEW rather than a table.

When applied:

  • DDL schema generation (ensureCreated, db:push, migration generation) skips this entity.
  • DbSet write operations (add, addRange, update, remove) throw a DbException at runtime.
  • DbSet read operations (toList, find, where, count, etc.) work normally via SELECT.

Parameters​

ParameterTypeDescription
viewNamestringThe exact name of the database view.

Returns​

ClassDecorator

Usecase​

Expose pre-aggregated or joined views as typed, read-only query targets.

Example​

@ViewEntity('v_active_orders')
export class ActiveOrder {
@Column()
id!: number;

@Column()
customerName!: string;

@Column()
total!: number;
}

// Usage
const orders = await ctx.set(ActiveOrder).where(o => o.total > 500).toList();