Do you really need an ORM?

I'm designing a Next app with a postgres DB in supabase, and want to use tRPC so I have some methods I can share to other apps I might make in future (using React Native or something). I've got the db defined in supabase - there's a bunch of tools that make that super easy - then I can use supabase typegen to make the requisite types. Then I can create tRPC methods using those types. So what's the use in an ORM like prisma or drizzle? What is it adding?
8 Replies
TROGLO
TROGLO6d ago
From my understanding, Supabase is designed for headless apps and provides an easy way to let users read from and write to the database. However, if you develop an API to act as an intermediary between your frontend and the database, you would typically need an ORM to manage the data interactions.
ChrisEvans
ChrisEvansOP6d ago
@TROGLO can you explain why it would be needed? I get that it generates some useful - and standardised - methods for querying the DB. But tRPC can effectively handle a lot of that (alright, it doesn;t make the methods for you, but the strict typing means it's very easy to set up those methods ina. typesafe way).
Ryan
Ryan6d ago
@ChrisEvans If you are using the Supabase client sdk then you are right! No need for an ORM the Supabase client library already provides this feature. On the other hand, ORM's can escape your SQL to prevent injection attacks (Supabase SDK also does this). ORM's often come with database migration features for when you want to alter your schema during deployment... (for e.g. https://orm.drizzle.team/docs/drizzle-kit-generate) Another feature that an ORM might provide is being able to migrate to an alternative database like MySQL or SQLite with less changes to your codebase, however this is quite rare and depends on your app. If you do decide to stay minimal, make sure your queries are espcaed correctly and consider a strategy for changes to your database schema...
ChrisEvans
ChrisEvansOP6d ago
Thanks for you input @Ryan - useful info. I have a related question for the gang: This app I'm building is a learning project. I want to use tooling that is common or best-practice for organisations, not just tooling that is good for personal projects. I'm primarily a FE dev with little experience using and managing databases. On that note: Are ORMs common practice, and worth learning?
Sameer
Sameer6d ago
Hi, I am also a frontend developer, and in my experience, ORMs are commonly used tools whenever interacting with a database. They are generally a nice abstraction to have when dealing with a DB.
Generally, ORMs make a lot of things simpler for us to handle, such as migrations, seeding, querying, and, of course, type safety.
I can say that learning an ORM won't be a waste of your time.
As for using tools that are common in organizations
Prisma seems to be one of the most widely used ORMs. Even Kysely appears to be an option for some organizations. Drizzle, on the other hand, is best suited for personal projects since it is relatively new and receives frequent major updates, unlike Prisma or Kysely.
Lyanor
Lyanor6d ago
@ChrisEvans Yes, ORMs are widely used in organizations, especially in large-scale applications where maintaining raw SQL queries can become cumbersome. They are common in backend development for handling database interactions in a structured, maintainable way.
ChrisEvans
ChrisEvansOP5d ago
blimey. I better use an ORM then.
Genio
Genio5d ago
Depends on ur usecase, me personally i mix between drizzle and supabase client with service role key But most of the time i find myself using supabase query, unless the query is not supported by supabase (highly unlikely) Because to me, supabase offers caching and alot of stuff preconfigured so its easy to query via the client Sometimes its nice to have type saftey when adding objects but i think both supabase and drizzle work perfectly and its helpful to have it in the background if you ever need to, you can query via drizzle instead of supabase

Did you find this page helpful?