Documentation

Getting started

Install pg-fluent, connect to PostgreSQL, and run Supabase-style queries with direct SQL execution.

pg-fluent is a server-side PostgreSQL client. It keeps the postgrest-js builder ergonomics and { data, error } result shape, but executes parameterized SQL directly over node-postgres.

Server-side only

Database credentials must never reach browsers or untrusted clients. pg-fluent runs as the connecting database role and does not emulate Supabase RLS role/JWT context. See Security & RLS.

Requirements

  • Node.js 22+ (LTS).
  • PostgreSQL 15–19.

Install

npm install pg-fluent

Optional peer dependencies (install only when you use the feature):

npm install pg-copy-streams    # db.copyFrom()
npm install @opentelemetry/api # telemetry: true

Quick start

import { createClient } from 'pg-fluent'

const db = createClient({
  connectionString: process.env.DATABASE_URL,
  schemas: ['public'],
})

const { data, error } = await db
  .from('users')
  .select('id, name')
  .eq('active', true)
  .order('name')

if (error) throw error
console.log(data)

await db.close()

Builders are lazy thenables: nothing executes until you await the chain. Results use the shape { data, error, count, status, statusText }. Query/database errors do not throw by default — check error or call .throwOnError().

Configuration

Pass a connection string or discrete fields. The first schema in schemas is the default schema used by from().

const db = createClient({
  connectionString: 'postgres://user:pass@host:5432/db',
  // or: host, port, database, user, password
  ssl: { rejectUnauthorized: true },

  schemas: ['public'],                 // exposed-schema allowlist; first is default
  pool: { max: 10, idleTimeoutMillis: 30_000, connectionTimeoutMillis: 5_000 },
  maxRows: 1000,                       // cap for read results (including explicit limits and embeds)
  statementTimeoutMs: 30_000,          // server-side statement_timeout (null = server default)
  retries: { max: 2, backoffMs: 50 },  // reads only
  allowUnfilteredMutations: false,

  // Observability (optional)
  logger,
  onQuery,
  logParams: false,
  redactColumns: ['password'],
  telemetry: false,
})
OptionDefaultNotes
schemas['public']Exposed schema allowlist. First entry is the default schema.
maxRows1000Caps read results, including explicit .limit()/.range() and embedded collections. An explicit limit above maxRows is reduced. Set Infinity to disable the cap.
statementTimeoutMs30000Server-side statement timeout. Use null for server default.
allowUnfilteredMutationsfalseWhen false, unfiltered UPDATE/DELETE without .select() is refused client-side.
retries{ max: 2, backoffMs: 50, idempotent: true }Read-only retries for transient connection/shutdown errors.
pool{ max: 10, ... }Pass pool options or an existing pg.Pool. pg-fluent does not close a pool it does not own.

Lifecycle

The underlying pool is exposed as db.$pool (read-only by convention). Close the client when your app shuts down:

await db.close({ timeoutMs: 5000 })

close() drains in-flight queries, ends owned pools, and stops LISTEN connections. It is idempotent. pg-fluent installs no implicit process-exit hooks.

Next steps

  • Guide — queries, embeds, writes, transactions, raw SQL, streaming, COPY, LISTEN/NOTIFY, replicas, and more.
  • API reference — config, client extras, builder methods, and CLI.
  • Security & RLS — the direct-connection security model.
  • Migrating from supabase-js — what to change and what to review.