Support views as relations with new migration generator
With the new generator, is it possible to reconsider supporting views in the ORM?
The generator fails since it tries to create a table that already exists as a view.
Originally posted by @mordechaim in #47
Idea
Perhaps, we can add a virtual = true to the table definition, which skips that table from the generator; also it will not allow calling await db.myView.create().
Currently, my view lives in a recurrent migration BTW.
Until now I've queried the view through a computed field in the parent table, using raw SQL with row_to_json to get the same result as an ORM relation.
But, as my application started scaling, the query got exceptionally slow. It turns out that the view — which is very complex; 523 lines of code — is super slow when run as a subquery (recalculating for each row) but very fast as lateral join. With computed fields I cannot define a lateral join, only subqueries.
I figured a workaround, via withSql I can pull the view into a CTE and then select through joining it to the main query. But I found it not to work, I'll open a separate issue for that.
#462
Surely views a good feature to support, will do, can't promise on timing. Seems to be not too complex.