lyonTypescript
lyonTypescript

Reputation: 135

NestJS How I make query to views in an database

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 {

}

My error logs in the console: enter image description here

Upvotes: 1

Views: 5459

Answers (1)

Robson Silva
Robson Silva

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

Related Questions