Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres
by gigatexal on Monday May 25, 2020 @02:51PM
(#23303707)
but select * is an anti-pattern. SQL queries should only return the columns that you need not that you might need -- usually. Lazy loading and sessions etc., like SQLAlchemy does to get around the N+1 query problem be damned.
[ Parent
| on HN ]
Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres
by renke1 on Monday May 25, 2020 @03:15PM
(#23303953)
I didn't mean the `SELECT STAR` in a literal sense, but more like, please select only the stuff we need. But indeed with PgTyped, as far as I understand it, it wouldn't work because it creates interface from SQL queries.
To achieve what I want you need to do it like all the other ORMs where you have some kind of description of your model and how it maps to tables and columns. Unlike the usual ORM I want to write SQL queries which are then rewritten in an intelligent manner.
So something like query(`SELECT STAR FROM user LEFT JOIN post …`, UserWithPostsModel). Since the library would know the target model, it could rewrite the `SELECT STAR` to something that only asks for the data it needs.
In other words I want to execute arbitrary queries that a mapped into ad-hoc models (unlike typical ORMs where the model usually maps directly to tables).
STAR = *