postgresqlmeta

package
v0.260.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

README

PostgreSQL Metadata Provider Module

PostgreSQL metadata provider used for optional metadata-aware DeltaScope audits against PostgreSQL.

Files

File Responsibility
open.go Formats PostgreSQL metadata connection DSNs and opens pgx stdlib database/sql handles
open_test.go Verifies TCP and unix-socket DSN/address formatting helpers
provider.go Loads normalized dialect, schema, instance-fact, table snapshot, and plain-EXPLAIN plan-estimate data from PostgreSQL catalogs and planner stats
provider_test.go Verifies catalog-backed schema discovery, reltuples/statistics loading, PK constraint truth, and plain-EXPLAIN estimation without a live database
resolve_object.go Resolves non-table database object metadata from PostgreSQL catalogs with schema-qualified ambiguity detection and privacy-safe attribute projection
resolve_object_test.go Verifies object resolver behavior for all supported lookup types, statuses, sensitive attribute exclusion, and annotation target verification

Exports

  • DefaultConnectTimeout
  • ConnectionConfig
  • OpenDBContext(ctx, config)
  • OpenDB(config)
  • Provider
  • NewProvider(db *sql.DB)
  • Provider.DetectDialect(ctx)
  • Provider.FindSchemasForTable(ctx, table)
  • Provider.LoadPlanEstimate(ctx, statement)
  • Provider.ResolveObject(ctx, dialect, request)

Dependencies

  • Upstream: internal/application/audit
  • Downstream: database/sql, github.com/jackc/pgx/v5, github.com/jackc/pgx/v5/stdlib, internal/domain/spec

Update Rule

  • If members/interfaces/dependencies change, update this file in same change.

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.

Index

Constants

View Source
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

func OpenDBContext(ctx context.Context, config ConnectionConfig) (*sql.DB, error)

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
	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

func NewProvider(db *sql.DB) *Provider

NewProvider builds a metadata provider on top of an existing SQL handle.

func (*Provider) DetectDialect

func (p *Provider) DetectDialect(ctx context.Context) (spec.Dialect, error)

DetectDialect reads server version information and classifies the SQL dialect.

func (*Provider) FindSchemasForTable

func (p *Provider) FindSchemasForTable(ctx context.Context, table string) ([]string, error)

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 (p *Provider) LoadTableSnapshot(ctx context.Context, _ spec.Dialect, schema string, table string) (*spec.TableSnapshot, error)

func (*Provider) ResolveObject added in v0.90.0

ResolveObject looks up non-table database object metadata from PostgreSQL catalogs.

func (*Provider) ResolveTableForIndex

func (p *Provider) ResolveTableForIndex(ctx context.Context, _ spec.Dialect, schema string, index string) (string, error)

LoadTableSnapshot reads one target table shape from PostgreSQL catalogs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL