Search code examples
sqlormsequelize.jsnestjstypeorm

How can I use raw SQL in NestJS instead of TypeOrm or Sequelize?


As of today TypeOrm has 1.493 issues over 282.102 weekly downloads and Sequelize 783 issues over 571.781 weekly downloads in Github.

As I read over the TypeOrm and Sequelize Github issues, I want to avoid those major problemas by coding raw SQL instead of dealing with major issues like losing data, columns being dropped when you synchronize entities or types being changed due to default ORM types.

I use NestJs 7.0.3 with TypeGraphQL, PostgreSQL v12.2 and TypeScript. Since 2019, I've had two issues raised with TypeOrm.

I understand the advantages of using an ORM but I wonder if NestJS can work efficiently if I use raw SQL in order to replace TypeORM or Sequelize entirely?

Thanks so much for your insights. Ron


Solution

  • You could always create your own Dynamic Module, using a database driver of your choice. I have a database module based off the node-pg package and have loved writing my own SQL for it. You can view the source code here. It's not a published package, but it should help you get to where you want.