Documentation
¶
Overview ¶
Public embedding surface: aliases that let external modules construct a Config, implement plugin hooks, and mount pdbr inside their own HTTP mux. The implementation stays under internal/; aliases are the contract.
Package pdbr wires the subsystems into a runnable application and is the embedding surface for third-party plugins: import pdbr as a library and run pdbr.New(cfg, pdbr.WithPlugins(myPlugin)).Serve(ctx).
Index ¶
- Constants
- func ExampleConfigYAML() string
- type APIBuilder
- type APIHook
- type App
- func (a *App) BuildAPI(ctx context.Context, cat *introspect.Catalog) (*api.Built, error)
- func (a *App) Close()
- func (a *App) CompileSQL(ctx context.Context, r *http.Request) (string, error)
- func (a *App) Connect(ctx context.Context) error
- func (a *App) Handler(ctx context.Context) (http.Handler, error)
- func (a *App) LoadCatalog(ctx context.Context) (*introspect.Catalog, error)
- func (a *App) Plugins() []plugin.Plugin
- func (a *App) Pool() *pgxpool.Pool
- func (a *App) ReadOnly() bool
- func (a *App) Runtime(built *api.Built) (*server.Runtime, error)
- func (a *App) Serve(ctx context.Context) error
- func (a *App) SetReadOnly(v bool)
- type AuthConfig
- type Built
- type Catalog
- type CatalogHook
- type CompileFunc
- type CompileHook
- type CompileRequest
- type Computed
- type Config
- type DatabaseConfig
- type ErrorsConfig
- type FiltersConfig
- type InflectInput
- type InflectKind
- type InflectNext
- type InflectionHook
- type LogConfig
- type Operation
- type Option
- type Plan
- type Plugin
- type PluginRegistry
- type PluginsConfig
- type Problem
- type RLSConfig
- type RPC
- type Relation
- type RequestHook
- type Resource
- type Result
- type Route
- type Runtime
- type SchemaConfig
- type ServerConfig
- type Statement
- type TXConfig
- type UserError
- type WatchConfig
Constants ¶
const ( KindResourcePath = inflect.KindResourcePath KindFieldName = inflect.KindFieldName KindRelationForward = inflect.KindRelationForward KindRelationBackward = inflect.KindRelationBackward KindRPCName = inflect.KindRPCName KindComputedField = inflect.KindComputedField KindEnumValue = inflect.KindEnumValue )
Inflection kinds pdbr asks the naming chain for.
Variables ¶
This section is empty.
Functions ¶
func ExampleConfigYAML ¶
func ExampleConfigYAML() string
ExampleConfigYAML renders the annotated reference configuration.
Types ¶
type APIBuilder ¶
Types referenced by hook signatures, the plan and the executor.
type App ¶
type App struct {
Config config.Config
Registry *plugin.Registry
Log *slog.Logger
Version string
// contains filtered or unexported fields
}
App is a configured pdbr instance.
func (*App) BuildAPI ¶
BuildAPI runs the model pipeline: catalog hooks -> inflection -> default generation -> API hooks -> Build. Warnings are logged as they arise.
func (*App) Close ¶
func (a *App) Close()
Close stops any running schema watcher, waits for it to release its connection, then closes the pool. It is idempotent, needs no prior Serve or Handler call, and does not require the context given to them to be cancelled first.
func (*App) CompileSQL ¶
CompileSQL runs the boot pipeline without connecting to the database (schema.cache_path, or a live catalog when no cache is configured) and returns the compiled statement for r in the golden format without executing it (pdbr request --print-sql). Routing, parse and compile failures come back as *exec.Error.
func (*App) Handler ¶
Handler runs the boot pipeline (catalog -> plugins -> api.Built -> runtime) and returns the http.Handler for embedding in a larger mux. Watch mode, when enabled, hot-swaps the runtime behind the returned handler exactly as Serve does.
func (*App) LoadCatalog ¶
LoadCatalog loads the schema cache when configured, else connects and introspects.
func (*App) Runtime ¶
Runtime assembles the server runtime for a built API: the compile chain (core compiler wrapped by CompileHooks), the executor over the pool, and the route handler. The pool may be nil (schema-cache boot without a database): requests then fail with 503, --print-sql still works.
func (*App) SetReadOnly ¶
SetReadOnly toggles read-only mode at runtime: when on, every write is answered with 405 (code read_only) before it compiles or touches the database. Safe for concurrent use; persists across watch-mode swaps.
type AuthConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type Catalog ¶
type Catalog = introspect.Catalog
Types referenced by hook signatures, the plan and the executor.
type CompileFunc ¶
Types referenced by hook signatures, the plan and the executor.
type CompileRequest ¶
Types referenced by hook signatures, the plan and the executor.
type Config ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type DatabaseConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type ErrorsConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type FiltersConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type InflectInput ¶
type InflectInput = coreinflect.Input
Types referenced by hook signatures, the plan and the executor.
type InflectKind ¶
type InflectKind = coreinflect.Kind
Types referenced by hook signatures, the plan and the executor.
type InflectNext ¶
type InflectNext = coreinflect.Next
Types referenced by hook signatures, the plan and the executor.
type LogConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type Option ¶
type Option func(*App)
Option customizes an App.
func WithPlugins ¶
WithPlugins registers additional plugins (the library embedding pattern).
func WithVersion ¶
WithVersion sets the version reported in the OpenAPI document.
type PluginsConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type RLSConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type SchemaConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type ServerConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type TXConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
type WatchConfig ¶
Configuration. Shared section types come from pdbcore/confx; Server is pdbr's own and Schema embeds the shared section (confx.Schema) with pdbr's own keys. Section types carry a Config suffix to avoid clashing with unrelated root-package names.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
pdbr
command
Command pdbr serves an automatically mapped REST API for a PostgreSQL database, and provides schema-cache, config, and one-off request tooling.
|
Command pdbr serves an automatically mapped REST API for a PostgreSQL database, and provides schema-cache, config, and one-off request tooling. |
|
internal
|
|
|
api
Package api turns an introspected catalog into pdbr's resource model: the resources, relations, computed columns, RPCs, enums and composites the server routes to, the lookup tables the parser and compiler consult, the route table, and the OpenAPI document.
|
Package api turns an introspected catalog into pdbr's resource model: the resources, relations, computed columns, RPCs, enums and composites the server routes to, the lookup tables the parser and compiler consult, the route table, and the OpenAPI document. |
|
compile
Package compile turns a plan.Request into exactly one parameterized SQL statement whose single json column `data` is the response body (or a small wrapper object around it, see Shape).
|
Package compile turns a plan.Request into exactly one parameterized SQL statement whose single json column `data` is the response body (or a small wrapper object around it, see Shape). |
|
config
Package config defines pdbr's configuration model and its loading rules: YAML file < environment (PDBR_*) < command-line flags.
|
Package config defines pdbr's configuration model and its loading rules: YAML file < environment (PDBR_*) < command-line flags. |
|
exec
Package exec is the thin glue between the compiled statement and pdbcore/pgexec: it builds the Operation RequestHooks see, applies the read-only gate and the cost limit, compiles through the CompileHook chain, decides the transaction policy, runs the statement, and unwraps the statement's data column into status, headers and body.
|
Package exec is the thin glue between the compiled statement and pdbcore/pgexec: it builds the Operation RequestHooks see, applies the read-only gate and the cost limit, compiles through the CompileHook chain, decides the transaction policy, runs the statement, and unwraps the statement's data column into status, headers and body. |
|
inflect
Package inflect declares pdbr's naming kinds and its default inflector: raw PostgreSQL identifiers everywhere (PostgREST-style), computed-column keys minus the `<table>_` prefix, relation keys equal to the referenced / referencing table name.
|
Package inflect declares pdbr's naming kinds and its default inflector: raw PostgreSQL identifiers everywhere (PostgREST-style), computed-column keys minus the `<table>_` prefix, relation keys equal to the referenced / referencing table name. |
|
parse
Package parse turns a matched HTTP request (method, route match, query string, headers) into a fully resolved plan.Request.
|
Package parse turns a matched HTTP request (method, route match, query string, headers) into a fully resolved plan.Request. |
|
plan
Package plan holds the transport-neutral request plan: what a parsed HTTP request asks for, with every name already resolved against api.Built.
|
Package plan holds the transport-neutral request plan: what a parsed HTTP request asks for, with every name already resolved against api.Built. |
|
plugin
Package plugin defines pdbr's REST-specific hook surfaces (APIHook, CompileHook, RequestHook) and a Registry that layers their chain helpers on pdbcore/plugin's Registry (Plugin, CatalogHook, InflectionHook).
|
Package plugin defines pdbr's REST-specific hook surfaces (APIHook, CompileHook, RequestHook) and a Registry that layers their chain helpers on pdbcore/plugin's Registry (Plugin, CatalogHook, InflectionHook). |
|
plugins/advancedfilters
Package advancedfilters is the built-in plugin that opens the relation and computed-column query surface: relation filters (rel.col=op.v, rel!none., rel!every., rel=exists.true|false), related-column ordering (order=rel(col).asc) and computed-column filter/order.
|
Package advancedfilters is the built-in plugin that opens the relation and computed-column query surface: relation filters (rel.col=op.v, rel!none., rel!every., rel=exists.true|false), related-column ordering (order=rel(col).asc) and computed-column filter/order. |
|
plugins/nestedmutations
Package nestedmutations is the built-in plugin (priority 200) that lets a single-object POST create or connect related rows in the same statement: forward relation keys take {"create": {…}} or {"connect": {…}}, backward keys {"create": [{…}, …]}, nested up to max_depth.
|
Package nestedmutations is the built-in plugin (priority 200) that lets a single-object POST create or connect related rows in the same statement: forward relation keys take {"create": {…}} or {"connect": {…}}, backward keys {"create": [{…}, …]}, nested up to max_depth. |
|
plugins/postgis
Package postgis is the built-in plugin (priority 160) that turns PostGIS geometry/geography columns into a query surface: spatial filter operators (st_*, bbox_*), derived pseudo-columns (<col>_area, <col>_centroid, ...), select= projection arguments (transform=, simplify=), distance ordering (order=<col>.dist with near=) and the spatial aggregate functions (col.extent(), col.union(), col.collect(), col.centroid(); with server.aggregates).
|
Package postgis is the built-in plugin (priority 160) that turns PostGIS geometry/geography columns into a query surface: spatial filter operators (st_*, bbox_*), derived pseudo-columns (<col>_area, <col>_centroid, ...), select= projection arguments (transform=, simplify=), distance ordering (order=<col>.dist with near=) and the spatial aggregate functions (col.extent(), col.union(), col.collect(), col.centroid(); with server.aggregates). |
|
plugins/smartcomments
Package smartcomments is the built-in smart-comments plugin: PostGraphile- style tags in database COMMENTs (@omit, @name, @deprecated, @fieldName, ...) customize the REST surface with plain DDL.
|
Package smartcomments is the built-in smart-comments plugin: PostGraphile- style tags in database COMMENTs (@omit, @name, @deprecated, @fieldName, ...) customize the REST surface with plain DDL. |
|
server
Package server exposes the REST API over HTTP: the router built from the api.Built route table under server.base_path, /healthz and /readyz at the root, GET {base}/openapi.json, problem+json errors, and the middleware chain (recover, timeout, CORS, gzip, body limit, auth).
|
Package server exposes the REST API over HTTP: the router built from the api.Built route table under server.base_path, /healthz and /readyz at the root, GET {base}/openapi.json, problem+json errors, and the middleware chain (recover, timeout, CORS, gzip, body limit, auth). |
|
testcatalog
Package testcatalog extends the shared pdbcore fixture catalog with the in-memory objects pdbr's hermetic tests need and the fixture database lacks.
|
Package testcatalog extends the shared pdbcore fixture catalog with the in-memory objects pdbr's hermetic tests need and the fixture database lacks. |