Documentation ¶
Index ¶
- Constants
- func BigintOrNull(n int64) pgtype.Int8
- func Date(t time.Time) pgtype.Date
- func IsConstraintError(err error, constraint string) bool
- func PBool(b *bool) pgtype.Bool
- func PInt2(n *int16) pgtype.Int2
- func PInt32(n *int32) pgtype.Int4
- func PText(s *string) pgtype.Text
- func PTime(t *time.Time) pgtype.Timestamptz
- func PUUID(u *uuid.UUID) pgtype.UUID
- func Rollback(tx pgx.Tx, outErr *error)
- func SafeRollback(ctx context.Context, logger *slog.Logger, tx pgx.Tx, txName string)deprecated
- func SetConnStringVariables(conn string, vars url.Values) (string, error)
- func Text(s string) pgtype.Text
- func TextOrNull(s string) pgtype.Text
- func Time(t time.Time) pgtype.Timestamptz
- func TimeOrNull(t time.Time) pgtype.Timestamptz
- func ToUUIDPointer(v pgtype.UUID) *uuid.UUID
- func UUID(u uuid.UUID) pgtype.UUID
- func WithTX(ctx context.Context, pool TransactionBeginner, fn func(tx pgx.Tx) error) (outErr error)
- type JobLock
- type JobLockOptions
- type JobLockState
- type TransactionBeginner
Constants ¶
const ( JobLockStateNone = "" JobLockStateHeld = "held" JobLockStateLost = "lost" JobLockStateReleased = "released" )
Variables ¶
This section is empty.
Functions ¶
func BigintOrNull ¶
BigintOrNull returns a pgtype.Int8 for the given value, but will return a Int8 value that represents null in the database if the value is zero.
func IsConstraintError ¶
IsConstraintError checks if an error was caused by a specific constraint violation.
func PInt2 ¶ added in v0.7.2
PInt2 returns a pgtype.Int2 for the given value, but will return a Int2 value that represents null in the database if the value is nil.
func PTime ¶ added in v0.7.2
func PTime(t *time.Time) pgtype.Timestamptz
PTime converts a stdlib *time.Time to a pgtype.Timestamptz.
func Rollback ¶ added in v0.15.1
func Rollback(tx pgx.Tx, outErr *error)
Rollback rolls back a transaction and joins the rollback error to the outError if the rollback fails. If the transaction already has been committed/closed it's not treated as an error.
Defer a call to Rollback directly after a transaction has been created. That will give you the guarantee that everything you've done will be rolled back if you return early before committing.
func SetConnStringVariables ¶
SetConnStringVariables parses a connection string URI and adds the given query string variables to it.
func TextOrNull ¶
TextOrNull returns a pgtype.Text for the given string, but will return a Text value that represents null in the database if the string is empty.
func Time ¶
func Time(t time.Time) pgtype.Timestamptz
Time converts a stdlib time.Time to a pgtype.Timestamptz.
func TimeOrNull ¶
func TimeOrNull(t time.Time) pgtype.Timestamptz
Time converts a stdlib time.Time to a pgtype.Timestamptz, but will return a Timestamptz that represents a null value in the database if t is zero.
func ToUUIDPointer ¶ added in v0.11.5
ToUUIDPointer converts a pgtype.UUID to a *uuid.UUID.
Types ¶
type JobLock ¶
type JobLock struct {
// contains filtered or unexported fields
}
JobLock helps separate processes coordinate who should be performing a (background) task through postgres.
func NewJobLock ¶
func NewJobLock( db *pgxpool.Pool, logger *slog.Logger, name string, opts JobLockOptions, ) (*JobLock, error)
NewJobLock creates a new job lock.
func (*JobLock) RunWithContext ¶
RunWithContext runs the provided function once the job lock has been acquired. The context provided to the function will be cancelled if the job lock is lost.
type JobLockOptions ¶ added in v0.7.0
type JobLockOptions struct { // PingInterval controls how often the job locked should be // pinged/renewed. Defaults to 10s. PingInterval time.Duration // StaleAfter controls after how long a time a held lock should be // considered stale and other clients will start attempting to steal // it. Must be longer than the ping interval. Defaults to four times the // ping interval. StaleAfter time.Duration // CheckInterval controls how often clients should check if a held lock // has become stale. Defaults to twice the ping interval. CheckInterval time.Duration // Timeout is the timeout that should be used for all lock // operations. Must be shorter than the ping interval. Defaults to half // the ping interval. Timeout time.Duration }
JobLockOptions controls how a job lock should behave.
type JobLockState ¶
type JobLockState string
type TransactionBeginner ¶
TransactionBeginner is the interface for something that can start a pgx transaction for use with WithTX().