Documentation
¶
Overview ¶
Package postgresqlmeta implements metadata-aware audit adapters over PostgreSQL. input: connection configs for PostgreSQL metadata reads output: pgx stdlib database/sql handles for metadata providers pos: infrastructure connection opener for PostgreSQL metadata access note: if this file changes, update this header and module README.md.
Package postgresqlmeta implements metadata-aware audit adapters over PostgreSQL. input: sql.DB access plus version/schema/table lookup requests and PostgreSQL catalog queries output: normalized instance facts, dialect detection, schema discovery, table snapshots, and plan estimates for application-level audit enrichment pos: infrastructure metadata adapter between database/sql and domain metadata specs note: if this file changes, update this header and module README.md.
Package postgresqlmeta provides a stub QueryAccessConnResolver when built without the postgresql tag. input: none (stub only) output: empty struct satisfying build constraints pos: infrastructure stub for non-PostgreSQL builds note: if this file changes, update this header and module README.md.
Index ¶
- Constants
- func OpenDB(config ConnectionConfig) (*sql.DB, error)
- func OpenDBContext(ctx context.Context, config ConnectionConfig) (*sql.DB, error)
- type ConnectionConfig
- type Provider
- func (p *Provider) DetectDialect(ctx context.Context) (spec.Dialect, error)
- func (p *Provider) FindSchemasForTable(ctx context.Context, table string) ([]string, error)
- func (p *Provider) LoadInstanceFacts(ctx context.Context, _ spec.Dialect, _ string) (*spec.InstanceFacts, error)
- func (p *Provider) LoadPlanEstimate(ctx context.Context, statement spec.Statement) (*spec.ImpactEstimate, error)
- func (p *Provider) LoadTableSnapshot(ctx context.Context, _ spec.Dialect, schema string, table string) (*spec.TableSnapshot, error)
- func (p *Provider) ResolveObject(ctx context.Context, _ spec.Dialect, req spec.ObjectLookupRequest) (*spec.ObjectSnapshot, error)
- func (p *Provider) ResolveTableForIndex(ctx context.Context, _ spec.Dialect, schema string, index string) (string, error)
- type QueryAccessConnResolver
Constants ¶
const DefaultConnectTimeout = 5 * time.Second
DefaultConnectTimeout is the default timeout for initial metadata connection.
Variables ¶
This section is empty.
Functions ¶
func OpenDB ¶
func OpenDB(config ConnectionConfig) (*sql.DB, error)
OpenDB connects to a PostgreSQL database for metadata reads using a background context. The caller is responsible for closing the returned *sql.DB.
func OpenDBContext ¶ added in v0.62.0
OpenDBContext connects to a PostgreSQL database for metadata reads, respecting the caller's context for cancellation and applying the configured connect timeout as a deadline. The caller is responsible for closing the returned *sql.DB.
Types ¶
type ConnectionConfig ¶
type ConnectionConfig struct {
Host string
Port int
Socket string
Database string
User string
Password string
SSLMode string
CACert *x509.CertPool // pre-parsed CA pool; only used when sslmode requires verification
ConnectTimeout time.Duration
}
ConnectionConfig describes one PostgreSQL metadata connection.
func (ConnectionConfig) Address ¶
func (c ConnectionConfig) Address() string
Address reports the driver address for the connection.
func (ConnectionConfig) DSN ¶
func (c ConnectionConfig) DSN() string
DSN formats the config for the pgx database/sql driver.
func (ConnectionConfig) DatabaseName ¶
func (c ConnectionConfig) DatabaseName() string
DatabaseName reports the configured database or the PostgreSQL default.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider loads metadata facts through a PostgreSQL SQL connection.
func NewProvider ¶
NewProvider builds a metadata provider on top of an existing SQL handle.
func (*Provider) DetectDialect ¶
DetectDialect reads server version information and classifies the SQL dialect.
func (*Provider) FindSchemasForTable ¶
FindSchemasForTable lists schemas that currently contain the named table.
func (*Provider) LoadInstanceFacts ¶
func (p *Provider) LoadInstanceFacts(ctx context.Context, _ spec.Dialect, _ string) (*spec.InstanceFacts, error)
LoadInstanceFacts reads server-level settings that influence audit behavior.
func (*Provider) LoadPlanEstimate ¶
func (p *Provider) LoadPlanEstimate(ctx context.Context, statement spec.Statement) (*spec.ImpactEstimate, error)
LoadPlanEstimate reads a conservative row estimate using plain EXPLAIN output.
func (*Provider) LoadTableSnapshot ¶
func (*Provider) ResolveObject ¶ added in v0.90.0
func (p *Provider) ResolveObject(ctx context.Context, _ spec.Dialect, req spec.ObjectLookupRequest) (*spec.ObjectSnapshot, error)
ResolveObject looks up non-table database object metadata from PostgreSQL catalogs.
type QueryAccessConnResolver ¶ added in v0.390.0
type QueryAccessConnResolver struct{}
QueryAccessConnResolver is not available without postgresql build tag.