Files
pgsql-broker/pkg/broker/adapter/database.go
warkanum 4c8e1066d4 feat(broker): migrations-based install, roles, RLS, and job dependency groups
Replace the ad-hoc tables/procedures install layout with versioned,
ordered SQL migrations tracked in broker_schema_migrations. Add
optional least-privilege role provisioning (--with-roles), multi-tenant
row-level security, lease-based job claiming with stale-lease recovery,
and job dependencies -- both by job id and by fan-in job group. Add
Docker/Compose support for running the broker and its test suite.
2026-09-17 22:09:41 +02:00

83 lines
2.5 KiB
Go

package adapter
import (
"context"
"database/sql"
)
// DBAdapter defines the interface for database operations
type DBAdapter interface {
// Connect establishes a connection to the database
Connect(ctx context.Context) error
// Close closes the database connection
Close() error
// Ping checks if the database is reachable
Ping(ctx context.Context) error
// Begin starts a new transaction
Begin(ctx context.Context) (DBTransaction, error)
// Conn returns a single physical connection pinned out of the pool, for
// session-scoped state (e.g. advisory locks) that must survive across
// calls. The caller owns it and must Close() it when done.
Conn(ctx context.Context) (*sql.Conn, error)
// Exec executes a query without returning rows
Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
// QueryRow executes a query that returns at most one row
QueryRow(ctx context.Context, query string, args ...interface{}) DBRow
// Query executes a query that returns rows
Query(ctx context.Context, query string, args ...interface{}) (DBRows, error)
// Listen starts listening on a PostgreSQL notification channel
Listen(ctx context.Context, channel string, handler NotificationHandler) error
// Unlisten stops listening on a channel
Unlisten(ctx context.Context, channel string) error
}
// DBTransaction defines the interface for database transactions
type DBTransaction interface {
// Exec executes a query within the transaction
Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
// QueryRow executes a query that returns at most one row within the transaction
QueryRow(ctx context.Context, query string, args ...interface{}) DBRow
// Query executes a query that returns rows within the transaction
Query(ctx context.Context, query string, args ...interface{}) (DBRows, error)
// Commit commits the transaction
Commit() error
// Rollback rolls back the transaction
Rollback() error
}
// DBRow defines the interface for scanning a single row
type DBRow interface {
Scan(dest ...interface{}) error
}
// DBRows defines the interface for scanning multiple rows
type DBRows interface {
Next() bool
Scan(dest ...interface{}) error
Close() error
Err() error
}
// Notification represents a PostgreSQL NOTIFY event
type Notification struct {
Channel string
Payload string
PID int
}
// NotificationHandler is called when a notification is received
type NotificationHandler func(notification *Notification)