Recommended ORM for supabase + Dart Flutter
Hi all,
I’m building a Flutter app that will have some straightforward (one-to-many, many-to-many, etc.) but important relationships.
Setting up constraints and foreign keys etc. in the PostgreSQL database itself isn’t a big issue (though I would like to use migrations rather than write SQL scripts manually, for CI/CD purposes)
I’m trying to decide how to represent the models and relationships in the code. Is there a recommended Object-Relational Mapping package that will work with Dart and supabase? Does supabase have methods that encapsulate more complex queries? My other option is to write the methods myself and split them up between the models and the repositories, but I’d rather use an existing package for this if it saves time.
Some options I’ve seen in the community:
- Prisma
- Dart Jaguar
- use the supabase built-in methods with custom PostgreSQL functions
ORMs/ODMs with which I’m familiar from other projects:
- ActiveRecord (Ruby on Rails)
- Eloquent (PHP)
- mongoose (mongodb and Node.js)
Is there enough out of the box with supabase to just use the built-in methods and add my own model methods and repositories, or is there an ORM that pairs well with supabase and Flutter? Do we have best practices around this yet?
Thanks! :supafire:
4 Replies
The Supabase API is interfacing with PostgREST not the database directly. I haven't tried to use an ORM against any of them but unless they talk about integrating with PostgREST I'm thinking "no"
Prisma probably would be the closest place to look for that since it supports NoSQL DBs and the response from PostgREST is JSON.
I've been interfacing with it directly and handling the JSON conversion as I would from any other REST interface implementation
Prisma Dart appears to support GraphQL (browsing source code but not listed as a compatibility in their project tags) and Supabase does to so that may be a route you could take as well. I haven't personally tried either though https://supabase.com/docs/guides/api#graphql-api
APIs | Supabase
Auto-generating and Realtime APIs.
Prisma proper (which Prisma Dart is using underneath) and Supabase integration was being tracked in this GitHub discussion as well: https://github.com/supabase/supabase/discussions/7659
GitHub
Supabase and Prisma workflow compilation · Discussion #7659 · supab...
Note: This is a updated copy from the discord's help channel to increase visibility. I hope this can also be a central source for pointing to Prisma issues and workaround. Cross-posted to p...
Thanks for the detailed answer. I’ll do some more digging into PostgREST etc. Appreciate it.