来自 NestJS/TypeORM 项目的物化视图 [英] Materialized View from NestJS/TypeORM project

查看:74
本文介绍了来自 NestJS/TypeORM 项目的物化视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 TypeORM 从我的 NestJS 应用程序创建物化视图.数据库是一个 Postgres.

I'm trying to create a Materialized view from my NestJS app using TypeORM. The database is a Postgres.

遗憾的是查看实体不符合要求:https://www.bookstack.cn/read/TypeORM/view-entities.md

View Entities unfortunately doesn't match requirements: https://www.bookstack.cn/read/TypeORM/view-entities.md

期望的行为:就像模型一样,在 NestJS 项目中定义了一个物化视图,带有选项 'synchronize:true' :项目在运行时创建视图,如果它不存在,如果存在,它只是同步使用它(就像模型一样).

Wished behaviour: just like models, a materialized view is defined in the NestJS project, with the option 'synchronize:true' : the project creates the view on running if it doesn't exist, if it exist, it just sync with it (just like models).

是否有任何线索可以帮助我实现这一目标?

Is there any leads that would help me achieving this?

推荐答案

我最终做的是将实体定义为 ViewEntity,设置 {materialized:true}.

What I ended up doing was defining the entity as a ViewEntity, setting {materialized:true}.

然而,正如您所指出的,typeorm 并不能很好地处理这个问题.当我想更改实体中的内容时,我最终禁用了 ormconfiguration 中的同步并运行了迁移.

However, as you noted, typeorm doesn't handle this so well. I ended up disabling synchronization in the ormconfiguration and running migrations when I wanted to change things in the entity.

但是,一旦创建了实体,typeorm 就可以很好地开箱即用.

However, once the entity is created, typeorm works out of the box really well.

这篇关于来自 NestJS/TypeORM 项目的物化视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆