Documentation

Migrating from supabase-js

The query builder API is intentionally close. The main changes are the connection model and the security model.

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

  1. Replace client creation. Use a PostgreSQL connection string (or discrete credentials) instead of a Supabase project URL + anon key.
  2. Remove non-DB Supabase APIs. auth, storage, and functions are not provided by pg-fluent. Call those services directly if you still need them.
  3. Keep or regenerate types. You can keep a compatible Database type, or generate one from your live database with npx pg-fluent gen-types.
  4. Review RLS and roles. Connect with a least-privilege role appropriate for server-side direct access.
  5. 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

Areasupabase-js / PostgRESTpg-fluent
TransportHTTP to PostgRESTDirect PostgreSQL wire protocol (node-postgres)
URLs / keysProject URL + anon/service keyConnection string or discrete DB credentials
Auth / storage / edge functionsProvided by Supabase SDK/platformNot provided (database client only)
RLS / rolesPostgREST role/JWT contextRuns as the connecting DB role; Supabase role policies do not apply automatically
ViewsReadable via PostgRESTReadable; embedding views is unsupported in v1
Reserved filter namesCan be silently ignored in some casesRejected with PGFLUENT_INVALID_QUERY (safer; avoids unfiltered reads)
StreamingHTTP chunking patternsNative .stream() (server-side cursor)
ExtrasPlatform 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: use await query.toSQL().
  • For server-side use, prefer least-privilege DB roles and keep credentials in environment variables.