As we have seen so far, Supabase uses Postgres as the underlying database for its services. Aligned with its open-source-first philosophy, Supabase also ensures that the database can be used at its purest form. While Supabase spawns and maintains the database for a project, the developer has the freedom to choose from a wide range of options to interact with the database.
A direct connect to the Database
We can connect to the Postgres database in Supabase directly with the database credentials. When creating the project, Supabase asks the developer to select a database password. We can use that password along with host, port, user, and the database name, to connect to the database directly. There are plenty of platforms to connect to a Postgres database. One of the most popular and recommended in pgAdmin.
We can also use libraries such as node-postgres
to directly connect to the database in a Node.js project. We may also use a database ORM (such as Prisma) to interact with the database. ORMs often provide additional type safety and a powerful query API to interact with any database.
Connection pooling in a database
Connecting directly to the database is definitely flexible and powerful. Nonetheless, establishing a connection with the database is an expensive operation in time and resources for the database. Databases also have a limited number of connection slots. Optimizing database connection requests is even harder in a serverless application, since for each serverless invocation, it may require multiple temporary connections. This is where connection pooling comes in handy.