Supabase Database
Supabase provides a full PostgreSQL database for storing your app’s data. Create tables, write queries, and let your data scale.Prerequisites
- Supabase connected
- Basic understanding of your data needs
Creating Tables
In Supabase Dashboard
- Go to Table Editor in sidebar
- Click Create a new table
- Name your table (e.g.,
tasks) - Add columns
Via Nativeline
You can also ask Nativeline:Common Column Types
| Type | Use For | Example |
|---|---|---|
uuid | Unique IDs | Primary key, foreign keys |
text | Strings | Names, descriptions |
int4/int8 | Numbers | Counts, quantities |
bool | True/false | Is completed, is active |
timestamptz | Dates/times | Created at, due date |
jsonb | Complex data | Settings, metadata |
float8 | Decimals | Prices, coordinates |
Example: Tasks Table
Row Level Security (RLS)
Enable RLS
- Table Editor → Select table
- Toggle “RLS” to enabled
- Add policies
Common Policies
Users see only their data:CRUD Operations
Create (Insert)
Read (Select)
Update
Delete
Querying Data
Basic Queries
Filtering Options
| Method | Use | Example |
|---|---|---|
.eq() | Equals | eq("status", "active") |
.neq() | Not equals | neq("status", "deleted") |
.gt() | Greater than | gt("price", 100) |
.lt() | Less than | lt("age", 30) |
.gte() | Greater or equal | gte("rating", 4) |
.like() | Pattern match | like("name", "%John%") |
.in() | In array | in("status", ["active", "pending"]) |
.is() | Is null/bool | is("deleted_at", nil) |
Relationships
One-to-Many
Tasks belong to a category:Querying with Relationships
Handling Errors
Common Database Errors
| Error | Cause | Solution |
|---|---|---|
| RLS policy violation | No matching policy | Check your policies |
| Foreign key violation | Referenced row missing | Ensure referenced data exists |
| Not null violation | Required field empty | Provide all required fields |
| Unique violation | Duplicate value | Check for existing records |
Error Handling in App
Performance Tips
Add indexes for frequent queries
Add indexes for frequent queries
If you often query by a column (like
user_id), add an index:Select only needed columns
Select only needed columns
Instead of
select("*"), specify columns:Use pagination for large datasets
Use pagination for large datasets
Cache locally for speed
Cache locally for speed
Store frequently-accessed data locally and sync with Supabase.
Testing Database Operations
In Supabase Dashboard
- Table Editor → Select table
- View, add, edit, delete rows manually
- Great for testing and debugging
Via SQL Editor
- SQL Editor in Supabase sidebar
- Write and run queries directly
- Test policies and queries