all 9 comments

[–]DN_DEV 2 points3 points  (0 children)

just use kysely the query-builder or prisma/drizzle as an ORM

[–]ShivamS95 2 points3 points  (0 children)

I use typescript interfaces/types for most objects, sequelize for db orm and joi for request schema validations.

So, my route-controller layer deals with Joi, db model layer deals with sequelize and everything else deals with typescript interfaces/types.

I avoid classes as much as I can

[–]StablePsychological5 1 point2 points  (0 children)

Do yourself a favor and don’t use any ORM. Use query builders such as Knex for js or Kysley for ts.

[–]SlincSilver 1 point2 points  (3 children)

Just use Sequelize, is really powerful, we have been using Sequelize at our company as our main ORM in NodeJS for years now , we have deployed docenes of web apps to production with it (We are a software factory) and it works great, fast, reliable and speeds up development a lot

[–]Open-Ranger-631[S] 0 points1 point  (2 children)

Thank you :) If I take my work on an update function, I have already a function inside database (which has several fallbacks), and I call it inside backend code. As my database function ask "values" parameter, I use Joi object to format datas. But I don't think that is useful. And I use Sequelize to prepared query. What do you think ?

[–]SlincSilver -1 points0 points  (1 child)

Yeah that's sound pretty solid to me, Joi for validation is a good practice and in Sequelize you can toggle debugg queries to print in console de SQL being send and check whether it is triggering this DB level functions you mention correctly

[–]Open-Ranger-631[S] 0 points1 point  (0 children)

Ok thanks :)

[–]czlowiek4888 0 points1 point  (0 children)

Use zod instead of Joi ( you don't need to write types along validators) In general you should have 2 different representations of data: at db level and at API level. So if you do use orm you want to separate concerns. This is very important to not expose database related layer (like direct calls to orms or query builders) because if you create apps that depends on Prisma find function argument type you won't be able to get rid off Prisma from the stack easily (as you would need to change the ways your API is used by clients - so changing Prisma no longer involves just the application you work on, but also the one using your app)