Reputation: 135
I have one small problem, my question is how I make query to views in an database?. I'm based in this example enter link description here
My Code is one entity:
import { ViewEntity, Connection } from 'typeorm';
@ViewEntity({
expression: (connection: Connection) => connection.createQueryBuilder()
.select('id')
.from(V1, 'v1'), })
}
export class V1 {
}
Upvotes: 1
Views: 5459
Reputation: 36
You can use View Entities, as a said in updated docs: https://typeorm.io/#/view-entities
Ex:
@ViewEntity({
expression: (connection: Connection) => connection.createQueryBuilder()
.select("post.id", "id")
.addSelect("post.name", "name")
.addSelect("category.name", "categoryName")
.from(Post, "post")
.leftJoin(Category, "category", "category.id = post.categoryId")
})
Upvotes: 2