pdbr serve run the API server
pdbr request METHOD PATH [flags] one-off request, body to stdout
pdbr schema dump|check|print schema cache + OpenAPI tools
pdbr config init|validate|example configuration tools
pdbr plugins list registered plugins + hooks
pdbr completion bash|zsh|fish|powershell shell completion script
pdbr --version print the version
All commands accept --config plus the config-path flags (--database.url,
--server.base_path, ...; full list in
configuration.md).
Loads config, connects (or boots from --schema.cache_path), builds the API
and listens on server.addr until SIGINT/SIGTERM, then shuts down
gracefully (10s). An incomplete auth configuration (jwt mode without a
secret, headers mode without trusted proxies, an unreadable secret file) is
a startup error. Startup warnings (roles.switch off, empty
roles.allowed, suppressed bare aliases, skipped overloads) go to the log.
$ pdbr serve
$ pdbr serve --database.url postgres://... --server.base_path "" --watch.enabledRuns a single request through the real handler in-process — no listener, no HTTP client — and prints the result. Pipe-friendly.
pdbr request METHOD PATH [--body @file|-|'{json}'] [--header 'K: V']... [--accept text/csv] [--role NAME] [--claims '{json}'] [-i] [--print-sql]
PATHmay omitserver.base_path:/users?select=idand/users?select=idare the same request. Everything after?is the query string, so quote it for the shell.--bodytakes inline JSON,@file, or-for stdin. Bodies are sent asapplication/json.--header 'K: V'is repeatable (Prefer,If-Match,If-None-Match,Accept-Encoding, ...).--accept text/csvis shorthand for--header 'Accept: text/csv'.- By default the request runs as the connection role, without
credentials:
pdbr requestforcesauth.mode: noneandroles.switch: falseafter loading the config and before validating it, so it works on a default config without a JWT secret. No role is switched and no claims are set, so row-level security policies for request roles do not apply. --role NAMEruns the request as that role, as a server withauth.mode: none,roles.switch: trueandroles.anonymous: NAMEwould:SET LOCAL ROLEinside the request's transaction. The connection role must be able to switch to it;none,public,pg_*roles and names outside[A-Za-z0-9_]+are refused before connecting.roles.alloweddoes not apply (it restricts roles taken from credentials).--claims '{"user_id": 1}'sets the request's claims, a JSON object, exposed to SQL exactly as for an authenticated request: oneclaims.prefixsetting per claim (current_setting('jwt.claims.user_id', true)) and the whole object inclaims.json_settingwhen that is set. With both flags,pdbr request GET /posts --role app_user --claims '{"user_id": 1}'reproduces what that user's token would see.--roleand--claimsdo not change--print-sqloutput: the identity is applied by statements around the request's one statement, not in its text.- Output: the status line goes to stderr, the body to stdout;
-ialso prints response headers (sorted by name) to stdout before the body, then a blank line (likecurl -i). CSV bodies (--accept text/csv) are streamed verbatim (RFC 4180, CRLF line ends).
$ pdbr request GET '/users?select=id,email,posts(title)&limit=2'
$ pdbr request GET /users/1 -i
$ pdbr request POST /users --body '{"email":"a@b.c"}'
$ pdbr request POST /users --body @user.json --header 'Prefer: return=minimal'
$ echo '{"title":"x","author_id":1}' | pdbr request POST /posts --body -
$ pdbr request PATCH /users/1 --body '{"full_name":"Ann"}' --header 'If-Match: W/"9f2c..."'
$ pdbr request DELETE /users/1
$ pdbr request GET /posts --role app_user --claims '{"user_id": 1}'
$ pdbr request GET '/rpc/search_posts?q=pg'
$ pdbr request GET '/posts?select=id,title' --accept text/csv > posts.csv
$ pdbr request GET /openapi.json > openapi.jsonExit codes: 0 on 2xx/3xx, 1 transport/config error (bad config, no
database, cache mismatch), 2 on any 4xx/5xx — the problem body is still
printed to stdout, so scripts can distinguish "down" from "bad request" and
still read the code.
--print-sql prints the compiled statement and its parameter list instead of
executing it. Parsing, coercion and planning run exactly as they would for a
real request, so what you see is exactly what would run:
$ pdbr request GET '/users?select=id,email&mood=eq.happy&limit=2' --print-sql
-- request: GET /users?select=id,email&mood=eq.happy&limit=2
SELECT coalesce(json_agg(...), '[]'::json) AS data FROM ...
-- args: ["happy",2]The format is -- request: METHOD PATH\n<SQL>\n-- args: [json]\n — identical
to the golden files in internal/compile/testdata, so a .sql golden and
--print-sql output for the same request diff clean. Nothing is executed
(mutations and volatile RPCs are safe to inspect); combined with
--schema.cache_path it needs no database connection at all. Requests that
never reach the compiler (/openapi.json, /healthz, a 405) print no
SQL and exit 2 with the problem body when applicable.
$ pdbr schema dump -o schema.cache # introspect + write versioned cache
$ pdbr schema check --cache schema.cache # exit 1 on drift (CI gate)
$ pdbr schema print # OpenAPI 3.1 JSON to stdout
$ pdbr schema print --yaml # same document as YAML
$ pdbr schema print --contract public # the document of one configured contractprint --contract <name> renders the OpenAPI document of a contract from
the contracts config list instead of the full API (see
contracts.md).
dump and check never serve requests, so like pdbr request they run as
the connection role without credentials (auth.mode: none,
roles.switch: false are forced before validation) and need no JWT
secret. print validates the configuration as serve would, since the
document reflects auth.mode (pass --auth.mode=none to print without a
secret, matching a server in that mode).
dump always introspects the live database (it ignores schema.cache_path)
and writes the gzipped catalog envelope. check loads the cache, introspects
live, and prints a line-per-difference report on drift:
schema drift detected: cache 3e1f0a9c2b7d != live 88ad41c0e5f2
table public.users: column phone added (text)
function public.search_posts changed
print emits the same document as GET {base}/openapi.json (see
openapi.md; the e2e suite asserts the two are byte-identical);
with --schema.cache_path it needs no database. --yaml re-encodes the JSON
document as YAML in the same key order (api.Document.YAML), so JSON and
YAML always carry the same content in the same order.
Cache files are produced by pdbcore and interchangeable with pdbq — see
caching.md.
$ pdbr config init # write a starter pdbr.yaml (refuses to overwrite)
$ pdbr config validate # load defaults+file+env+flags, run every validation rule
$ pdbr config example # print the annotated reference generated from struct tagsexample needs no config or database; make example-config redirects it to
examples/pdbr.example.yaml. See
configuration.md for the checks
validate runs.
$ pdbr plugins list
smart_comments priority=50 enabled hooks: catalog, inflection, api
advanced_filters priority=150 enabled hooks: api
postgis priority=160 enabled hooks: api
nested_mutations priority=200 enabled hooks: api, compile, requestWith plugins.disabled: [nested_mutations] the last line reads
nested_mutations priority=200 disabled hooks: api, compile, request.
Format: %-20s priority=%-4d %-8s hooks: %s — name, priority, enabled /
disabled (per plugins.disabled), then the hooks the plugin implements
(catalog, inflection, api, compile, request). Runs as the
connection role without credentials like pdbr request, so it needs no JWT
secret; an invalid configuration otherwise (an unknown name in
plugins.disabled, an unknown key) is reported. See plugins.md.
pdbr completion bash|zsh|fish|powershell prints a completion script for the
given shell (cobra's generator). Flag values with a fixed vocabulary complete
too, on every subcommand that takes them: --errors.detail → dev prod strict, --log.level → debug info warn error.
# bash (requires bash-completion)
$ pdbr completion bash > /etc/bash_completion.d/pdbr
# zsh
$ pdbr completion zsh > "${fpath[1]}/_pdbr"
# fish
$ pdbr completion fish > ~/.config/fish/completions/pdbr.fishRun pdbr completion <shell> --help for per-shell install notes.
Bodies are plain JSON on stdout, so jq composes naturally:
# emails of the first 100 users
$ pdbr request GET '/users?select=email' | jq -r '.[].email'
# walk every page with keyset cursors
$ cur=""; while :; do
out=$(pdbr request GET "/posts?select=id&limit=100${cur:+&after=$cur}" -i)
printf '%s\n' "$out" | sed '1,/^$/d' | jq -c '.[]'
cur=$(printf '%s\n' "$out" | awk 'tolower($1)=="x-next-cursor:"{print $2}' | tr -d '\r')
[ -n "$cur" ] || break
done
# create from a JSON file, capture the new id
$ id=$(pdbr request POST /users --body @user.json | jq -r '.id')
# error code without parsing stderr
$ pdbr request GET /users/999999 | jq -r '.code' # not_found (exit 2)
# CI: fail on drift, show the report
$ pdbr schema check --cache schema.cache || exit 1
# feed the OpenAPI document to a generator
$ pdbr schema print --schema.cache_path schema.cache > openapi.json--print-sql in a git diff-style review:
$ pdbr request GET '/users?select=*,posts(*)' --print-sql > /tmp/a.sql
$ pdbr request GET '/users?select=*,posts!inner(*)' --print-sql > /tmp/b.sql
$ diff /tmp/a.sql /tmp/b.sql