Review RLS before switching
pg-fluent runs as the connecting database role. It does not apply Supabase anon/authenticated role or JWT claim context. Policies written for Supabase may not protect a direct connection. Read Security & RLS first.
Migration steps
- Replace client creation. Use a PostgreSQL connection string (or discrete credentials) instead of a Supabase project URL + anon key.
- Remove non-DB Supabase APIs.
auth,storage, andfunctionsare not provided by pg-fluent. Call those services directly if you still need them. - Keep or regenerate types. You can keep a compatible
Databasetype, or generate one from your live database withnpx pg-fluent gen-types. - Review RLS and roles. Connect with a least-privilege role appropriate for server-side direct access.
- Test query behavior. Especially embeds, filters, writes, error handling, and any code that assumed PostgREST HTTP behavior.
// Before (supabase-js)
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY)
// After (pg-fluent)
import { createClient } from 'pg-fluent'
const db = createClient({ connectionString: process.env.DATABASE_URL })
What differs
| Area | supabase-js / PostgREST | pg-fluent |
|---|---|---|
| Transport | HTTP to PostgREST | Direct PostgreSQL wire protocol (node-postgres) |
| URLs / keys | Project URL + anon/service key | Connection string or discrete DB credentials |
| Auth / storage / edge functions | Provided by Supabase SDK/platform | Not provided (database client only) |
| RLS / roles | PostgREST role/JWT context | Runs as the connecting DB role; Supabase role policies do not apply automatically |
| Views | Readable via PostgREST | Readable; embedding views is unsupported in v1 |
| Reserved filter names | Can be silently ignored in some cases | Rejected with PGFLUENT_INVALID_QUERY (safer; avoids unfiltered reads) |
| Streaming | HTTP chunking patterns | Native .stream() (server-side cursor) |
| Extras | Platform APIs | .toSQL(), safe mutations, transactions/savepoints, raw SQL, COPY, LISTEN/NOTIFY, named connections, replicas |
Practical notes
- Query builders are lazy thenables — await them to execute.
- Results keep the
{ data, error, count, status, statusText }shape. .toSQL()is async in pg-fluent: useawait query.toSQL().- For server-side use, prefer least-privilege DB roles and keep credentials in environment variables.