Documentation
¶
Overview ¶
Package postgres runs host-mediated PostgreSQL queries via pgx on the operator.
Index ¶
- func IsReadonlySQL(sql string) bool
- func LogAudit(ev AuditEvent)
- func ParseParams(raw json.RawMessage) ([]any, error)
- func Ping(ctx context.Context, pools *PoolManager, dsn string, timeout time.Duration) error
- func RewriteDSNHostPort(dsn, hostOverride, portOverride string) (string, error)
- func ValidateParamPlaceholders(sql string, n int) error
- func ValidateReadonlySQL(sql string) error
- type AuditEvent
- type ExecOpts
- type ExecResult
- type MigrateOpts
- type MigrateResult
- type PoolManager
- type QueryOpts
- type QueryResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsReadonlySQL ¶
IsReadonlySQL reports whether sql passes the read-only classifier.
func LogAudit ¶
func LogAudit(ev AuditEvent)
LogAudit emits a structured audit log line (SQL hash + truncated preview, never DSN/params).
func ParseParams ¶
func ParseParams(raw json.RawMessage) ([]any, error)
ParseParams unmarshals params JSON into pgx query arguments.
func RewriteDSNHostPort ¶
RewriteDSNHostPort replaces hostname and/or port in a postgres connection URL or DSN.
func ValidateParamPlaceholders ¶
ValidateParamPlaceholders ensures sql uses $1..$n when args are present.
func ValidateReadonlySQL ¶
ValidateReadonlySQL returns nil when sql is a single read-only statement.
Types ¶
type AuditEvent ¶
type AuditEvent struct {
PluginID string
HostName string
Action string
SQL string
Readonly bool
DryRun bool
RowCount int
RowsAffected int64
}
AuditEvent describes a postgres host-function call for structured logging.
type ExecOpts ¶
type ExecOpts struct {
Timeout time.Duration
Readonly bool
PluginID string
HostName string
DryRun bool
}
ExecOpts configures a postgres exec.
type ExecResult ¶
type ExecResult struct {
RowsAffected int64
}
ExecResult holds rows affected from a write statement.
func Exec ¶
func Exec(ctx context.Context, pools *PoolManager, dsn, sql string, args []any, opts ExecOpts) (ExecResult, error)
Exec runs INSERT/UPDATE/DDL via pgx.
type MigrateOpts ¶
type MigrateOpts struct {
Timeout time.Duration
Readonly bool
PluginID string
HostName string
DryRun bool
}
MigrateOpts configures schema migration.
type MigrateResult ¶
MigrateResult summarizes applied migrations.
func Migrate ¶
func Migrate(ctx context.Context, pools *PoolManager, dsn, migrationsDir string, files []string, opts MigrateOpts) (MigrateResult, error)
Migrate applies ordered .sql files inside migrationsDir.
type PoolManager ¶
type PoolManager struct {
// contains filtered or unexported fields
}
PoolManager caches pgx pools keyed by DSN hash.
func NewPoolManager ¶
func NewPoolManager() *PoolManager
NewPoolManager creates an empty pool manager.
type QueryOpts ¶
type QueryOpts struct {
Timeout time.Duration
Readonly bool
PluginID string
HostName string
DryRun bool
}
QueryOpts configures a postgres query.
type QueryResult ¶
QueryResult holds rows from a SELECT-style query.
func Query ¶
func Query(ctx context.Context, pools *PoolManager, dsn, sql string, args []any, opts QueryOpts) (QueryResult, error)
Query runs a read-only SQL query via pgx.