Using PostgreSQL on a Dart server

Suragch
13 min readFeb 3, 2024

A tutorial on integrating the Dart Shelf server with a Postgres database

This article is another piece in the puzzle of self-hosting a backend server for a Flutter app. You may be interested in reading these related articles:

PocketBase might actually be all you need depending on your use-case, but at the time of this writing, PocketBase doesn’t support bulk inserts or updates and that’s something I need for an app I’m working on. My current plan is to still use PocketBase for user authentication but handle database operations separately with Shelf and PostgreSQL.

This is primarily a tutorial on using the postgres package. Using Shelf is not a requirement. Other good options include Dart Frog and Serverpod. In fact, Serverpod already includes PostgreSQL support, so if you’re going that route, you don’t even need to read this tutorial.

The reason I use Shelf is because it’s maintained by the Dart team. I don’t have to worry about it being abandoned or about the API changing much over the years. There are some ORM wrappers on Pub that you could use for postgres. But again, I don’t use them because I’m not sure if they’ll still be around in five years. Read Thoughts on using third-party

--

--