67 lines
No EOL
2.2 KiB
Markdown
67 lines
No EOL
2.2 KiB
Markdown
---
|
||
tags:
|
||
- iso27DIY
|
||
- dev
|
||
- SupaBase
|
||
---
|
||
# Building functionality in Supabase
|
||
Supabase offers several ways to build functionality beyond just SQL and Edge Functions. Here are the main approaches:
|
||
|
||
## Core Functionality Building Methods
|
||
|
||
**1. SQL Functions (Database Functions)**
|
||
|
||
- Postgres has built-in support for SQL functions that live inside your database and can be used with the API
|
||
- Created directly in the database using SQL
|
||
- Accessible via the Dashboard’s SQL editor
|
||
|
||
**2. Edge Functions**
|
||
|
||
- Deno-based serverless functions
|
||
- Run on the edge for low latency
|
||
- Good for custom business logic and integrations
|
||
|
||
**3. Database Functions & RPC (Remote Procedure Calls)**
|
||
|
||
- RPC in Supabase allows developers to invoke custom PostgreSQL functions directly from the client side, particularly useful for encapsulating complex operations
|
||
- RPC enables executing database functions directly, allowing batching of multiple operations into a single RPC call
|
||
- Called using the `.rpc()` method in client libraries
|
||
|
||
## Additional Functionality Methods
|
||
|
||
**4. Database Triggers**
|
||
|
||
- PostgreSQL triggers that automatically execute functions when certain database events occur
|
||
- Can be combined with SQL functions for automated workflows
|
||
|
||
**5. Row Level Security (RLS) Policies**
|
||
|
||
- Policy-based access control that acts as business logic
|
||
- Enforces rules at the database level
|
||
|
||
**6. Auto-generated REST APIs**
|
||
|
||
- Automatic CRUD operations based on your database schema
|
||
- No additional code needed for basic operations
|
||
|
||
**7. Real-time Subscriptions**
|
||
|
||
- Listen to database changes in real-time
|
||
- Automatically generated based on your tables and RLS policies
|
||
|
||
**8. GraphQL API**
|
||
|
||
- Auto-generated GraphQL APIs available alongside REST
|
||
- Provides flexible querying capabilities
|
||
|
||
**9. Webhooks**
|
||
|
||
- Database webhooks that can trigger external services
|
||
- Can be set up to respond to database events
|
||
|
||
**10. PostgREST Extensions**
|
||
|
||
- Custom PostgreSQL extensions that extend functionality
|
||
- Can be installed to add specialized features
|
||
|
||
The most common approaches for custom business logic are SQL functions (accessed via RPC), Edge Functions, and database triggers, with each serving different use cases depending on where you want the logic to run and how complex your requirements are. |