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. DbSetwrite operations (add,addRange,update,remove) throw aDbExceptionat runtime.DbSetread operations (toList,find,where,count, etc.) work normally viaSELECT.
Parameters
| Parameter | Type | Description |
|---|---|---|
viewName | string | The 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();