Skip to main content

Integrate the Supabase

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Supabase is built on a standard PostgreSQL database, giving you the flexibility to interact with it using various tools and methods. This guide explores how to integrate with Supabase, extend its functionality, and choose the right method for different tasks.


Connecting to Supabase as a Traditional Postgres Database

Yes, you can absolutely connect to your Supabase project using any standard PostgreSQL client or library. This is one of Supabase's greatest strengths: it doesn't lock you into a proprietary ecosystem.

You can find the connection strings for your database in your Supabase project's settings. Supabase provides several types of connection strings to optimize for different use cases:

  • Direct Connection String: This connects directly to your PostgreSQL instance. It's best for long-running, persistent services like a backend server running on a VM.
  • Supavisor Connection String: This connects through Supabase's built-in connection pooler, Supavisor. This is ideal for serverless or edge functions that create and close connections frequently, as it reuses connections to prevent resource exhaustion on the database [1].

With these connection strings, you can use any tool you're familiar with, such as psql, pgAdmin, DBeaver, or ORMs like Prisma and Drizzle, to manage and interact with your database.


GraphQL with Supabase

Yes, Supabase has native GraphQL support through the pg_graphql extension, which is available on all projects [3].

Unlike other platforms that require a separate GraphQL server, pg_graphql is an extension that runs directly inside your PostgreSQL database. It reads your SQL schema and automatically exposes a GraphQL API [3].

You can:

  • Use the GraphiQL interface in the Supabase Dashboard to explore your GraphQL schema and run queries.
  • Make GraphQL requests directly to a dedicated /graphql/v1 endpoint.
  • The GraphQL API automatically enforces your existing Row-Level Security (RLS) policies, so you don't have to rebuild your security layer for GraphQL [3].

While Supabase's client libraries primarily use REST and RPC, GraphQL offers an alternative for applications that benefit from its declarative querying and schema-first approach.


Webhooks and Database Change Events

Supabase provides a powerful feature called Database Webhooks to handle database change events [5].

A database webhook allows you to trigger an external HTTP request whenever a specified event (INSERT, UPDATE, or DELETE) occurs on a table [5]. This is an ideal way to integrate your Supabase database with external services like a payment processor, a notification system, or a data warehouse.

  • How it works: Database Webhooks are built on the pg_net PostgreSQL extension [6]. This extension allows a database to make asynchronous HTTP requests, meaning the database operation (e.g., an INSERT) completes immediately, and the webhook request is processed in the background. This prevents slow network requests from blocking your database transactions [5].

You can create webhooks directly from the Supabase Dashboard or via SQL statements.


Triggers, Edge Functions, and Background Workers

Supabase offers three distinct ways to execute server-side logic. Choosing the right one depends on your use case.

FeatureBest for...Execution ContextHow it works
Database TriggersData validation, auditing, and enforcing rules directly within the database transaction.Synchronous, inside the database.A trigger is a stored procedure that automatically runs when a database event occurs on a table. It runs as part of the transaction, so if the trigger fails, the entire transaction rolls back [6].
Edge FunctionsCreating custom API endpoints, handling webhooks, and integrating with third-party services.Asynchronous, globally distributed at the "edge".These are serverless functions written in TypeScript (using Deno) that run on demand via an HTTP request. They are ideal for business logic that sits outside of the database [6].
Background WorkersLong-running, asynchronous jobs like sending emails, processing large files, or performing complex calculations.Asynchronous, triggered on a schedule or by an event.Supabase allows you to set up background workers by combining different features. You can use a database trigger to insert a job into a queue table, and then use a scheduled Edge Function (via pg_cron) or a dedicated worker to process the queue [6, 7]. This decouples the long-running task from the user's request.

The key difference lies in their tightness of coupling. Triggers are tightly coupled to database transactions, Edge Functions are loosely coupled via an HTTP request, and background workers are fully decoupled for non-blocking operations.

Sources

  1. Supabase. "Connect to your database | Supabase Docs". https://supabase.com/docs/guides/database/connecting-to-postgres
  2. Supabase. "PostgREST and Supabase APIs". https://supabase.com/docs/guides/api
  3. Supabase. "GraphQL | Supabase Docs". https://supabase.com/docs/guides/graphql
  4. Supabase. "How pg_graphql works - Supabase". https://supabase.com/blog/how-pg-graphql-works
  5. Supabase. "Database Webhooks | Supabase Features". https://supabase.com/features/database-webhooks
  6. Supabase. "What's the difference in Trigger+function vs Database Webhooks extension". https://www.reddit.com/r/Supabase/comments/1l5odpw/whats_the_difference_in_triggerfunction_vs/
  7. Supabase. "Hacking together a Job Runner using Supabase Edge Functions". https://duggan.ie/posts/hacking-together-a-job-runner-using-supabase-edge-functions