Skip to content

pbkit command-line interface reference.

Generate types and SDK from your pbkit.config.ts.

Terminal window
bunx pbkit generate
FlagShortDescription
--config <path>-cPath to a config file (defaults to auto-detection)
--watch-wWatch mode — regenerates every 10 seconds
--help-hShow help message

Manage PocketBase collection definitions directly against the admin API (/api/collections). Schema-only — record CRUD is intentionally out of scope.

Terminal window
pbkit schema list # list all collections (name + type)
pbkit schema get <collection> # dump one collection as JSON
pbkit schema pull [--out pb-schema.json]# download the full snapshot the generator reads
pbkit schema apply <file.json> # import definitions (non-destructive)
pbkit schema add-field <collection> <json>
pbkit schema add-index <collection> "<sql>"
pbkit schema set-rule <collection> [--list <rule>] [--view <rule>] [--create <rule>] [--update <rule>] [--delete <rule>]
pbkit schema create-view <name> --query "<sql>"
CommandDescription
listList every collection with its name and type
get <collection>Print one collection (fields, indexes, rules, viewQuery) as JSON
pull [--out <file>]Write the full schema snapshot (default pb-schema.json) — the same shape pbkit generate consumes
apply <file>Import collection definitions via PUT /api/collections/import
add-field <collection> <json>Append a field, preserving the existing fields array
add-index <collection> "<sql>"Append an index, merging with existing indexes
set-rule <collection> --list/--view/--create/--update/--delete <rule>Update API rules (only the provided ones)
create-view <name> --query "<sql>"Create a view collection
FlagDescription
--config <path>Config file used for fallback URL/token (auth env vars take precedence)
--out <file>Output path for pull (default pb-schema.json)
--delete-missingFor apply, remove collections absent from the file (default off)
--query <sql>View query for create-view
--list/--view/--create/--update/--delete <rule>Rules for set-rule

apply is non-destructive by default (deleteMissing: false). Partial operations (add-field, add-index, set-rule) fetch the current collection and patch it, so they never clobber unrelated fields, indexes, or rules. For set-rule, a rule value of "null" makes the rule superuser-only and "" makes it public.

Schema commands authenticate as a superuser (_superusers/auth-with-password). Credentials are read from the environment (preferred), falling back to the pbkit.config.ts API input — never inline.

VariablePurpose
POCKETBASE_URLPocketBase base URL
POCKETBASE_ADMIN_EMAILSuperuser email (used with the password)
POCKETBASE_ADMIN_PASSWORDSuperuser password
POCKETBASE_ADMIN_TOKENPre-issued admin token (alternative to email/password)

pbkit searches for a config file in the current working directory in this order:

  1. pbkit.config.ts
  2. pbkit.config.js
  3. pbkit.config.mjs
Terminal window
bunx pbkit generate --watch

In watch mode, pbkit polls the API (or re-reads the file) every 10 seconds and regenerates if the schema has changed. Press Ctrl+C to stop.

Terminal window
bunx pbkit generate --config ./configs/pbkit.config.ts
CodeMeaning
0Success
1Error (config not found, API error, invalid config)
$ bunx pbkit generate
src/generated/types.gen.ts
src/generated/client.gen.ts
src/generated/sdk.gen.ts
Generated 3 file(s) in 120ms