Documentation
¶
Overview ¶
Package database provides PostgreSQL connection management with multi-tenant RLS support.
Index ¶
- func GetUserID(ctx context.Context) (uuid.UUID, bool)
- func IsSuperadmin(ctx context.Context) bool
- func WithSuperadmin(ctx context.Context) context.Context
- func WithUser(ctx context.Context, userID uuid.UUID) context.Context
- type DB
- func (db *DB) Close()
- func (db *DB) ExecWithTimeout(ctx context.Context, timeout time.Duration, sql string, args ...any) error
- func (db *DB) GetConn(ctx context.Context) (*pgxpool.Conn, error)
- func (db *DB) Ping(ctx context.Context) error
- func (db *DB) Pool() *pgxpool.Pool
- func (db *DB) WithTx(ctx context.Context, fn func(tx pgx.Tx) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSuperadmin ¶
IsSuperadmin checks if the context has superadmin privileges.
func WithSuperadmin ¶
WithSuperadmin marks the context as having superadmin privileges.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps a pgx connection pool with tenant-aware operations.
func NewWithConfig ¶
NewWithConfig creates the pool from a ready pgx config, for callers that need a custom one (tests attach a pgx.QueryTracer to count statements).
func (*DB) ExecWithTimeout ¶
func (db *DB) ExecWithTimeout(ctx context.Context, timeout time.Duration, sql string, args ...any) error
ExecWithTimeout executes a query with a timeout.
func (*DB) GetConn ¶
GetConn returns a connection with tenant context configured for RLS. This is the primary way to acquire database connections.
Click to show internal directories.
Click to hide internal directories.