DEV Community

Discussion on: Repository Pattern with Typescript and Node.js

Collapse
 
fyapy profile image
aabdullin • Edited

Never worked with Prisma.

But i see one problems:

  1. Migrations support only SQL files. Yeah, in most cases like rename/add column it is enough. But we have cases when we need select data, and cardinaly change database schema and transform data, in this situations we need features like loops, primitive operations with strings/numbers. SQL support this too, but i find write JavaScript code much simpler and maintainable.

And the points because of which I do not consider Knex a bad choice:

  1. Goal of using of Knex query builder it is get predictable and readable query generator in low level implementation of repository, and get at the exit high level Data Layer with simple API for our needs.
  2. Yeah, Knex not have awesome TypeScript support, but it good enough. Especially because we write types for Repository methods arguments and outputs.

Repository pattern not a panacea, it all depends on your tasks 😉

Collapse
 
joaolss profile image
João Lucas Silva

The first argument is bad just because it is not a good choice to use webdev tools to do data engineer stuff, if you need big data manipulations in the samedatabase that you use to keep ordinary webapp data, something is structurally wrong

Thread Thread
 
petoru profile image
Petr Vnenk

That's a more than good argument, if we're talking about the same thing (the SQL-only migrations). In ideal world that wouldn't happen, but in real world I definitely came into scenario where yes, something was wrong with the database schema, but if you get to that point, having Prisma with its current toolset will screw you over and try then explaining that to the client. Having some other ORM with programatic migrations solves a huge pain point there because you are able to run any logical operations you wish over the database.

I am also not sure I completely follow your point though. Database migrations should definitely be handled by a single tool which ORM's are usually for.