Documentation
¶
Overview ¶
Package pgutil provides helpers for working with pgx (jackc/pgx).
Error checks ¶
IsNoRows reports whether err is or wraps pgx.ErrNoRows (use after QueryRow when a missing row is expected). IsPgErrorCode reports whether err is a PgError with the given SQLSTATE code. IsPgUniqueViolation, IsForeignKeyViolation, IsNotNullViolation are conveniences for common codes (23505, 23503, 23502).
Timestamp conversion ¶
pgx uses pgtype.Timestamptz for timestamp with time zone. TimestamptzToTime returns *time.Time or nil when invalid. TimestamptzToTimeZero returns time.Time or the zero value. TimeToTimestamptz converts *time.Time to pgtype.Timestamptz (invalid if nil). PtrTimeToTime dereferences a *time.Time or returns time.Time{} if nil.
Index ¶
- func IsForeignKeyViolation(err error) bool
- func IsNoRows(err error) bool
- func IsNotNullViolation(err error) bool
- func IsPgErrorCode(err error, code string) bool
- func IsPgUniqueViolation(err error) bool
- func PgErrorCode(err error) string
- func PtrTimeToTime(t *time.Time) time.Time
- func TimeToTimestamptz(t *time.Time) pgtype.Timestamptz
- func TimestamptzToTime(t pgtype.Timestamptz) *time.Time
- func TimestamptzToTimeZero(t pgtype.Timestamptz) time.Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsForeignKeyViolation ¶
IsForeignKeyViolation reports whether err is a PostgreSQL foreign key violation (SQLSTATE 23503).
func IsNoRows ¶
IsNoRows reports whether err is or wraps pgx.ErrNoRows. Use after QueryRow when a missing row is acceptable.
func IsNotNullViolation ¶
IsNotNullViolation reports whether err is a PostgreSQL not null violation (SQLSTATE 23502).
func IsPgErrorCode ¶
IsPgErrorCode reports whether err is or wraps a PgError with the given SQLSTATE code.
func IsPgUniqueViolation ¶
IsPgUniqueViolation reports whether err is a PostgreSQL unique constraint violation (SQLSTATE 23505).
func PgErrorCode ¶
PgErrorCode extracts the SQLSTATE code from err, or "" if err is not a PgError.
func PtrTimeToTime ¶
PtrTimeToTime returns *t, or time.Time{} if t is nil.
func TimeToTimestamptz ¶
func TimeToTimestamptz(t *time.Time) pgtype.Timestamptz
TimeToTimestamptz converts *time.Time to pgtype.Timestamptz. Returns an invalid Timestamptz if t is nil.
func TimestamptzToTime ¶
func TimestamptzToTime(t pgtype.Timestamptz) *time.Time
TimestamptzToTime returns a pointer to the time, or nil if t.Valid is false.
func TimestamptzToTimeZero ¶
func TimestamptzToTimeZero(t pgtype.Timestamptz) time.Time
TimestamptzToTimeZero returns t.Time, or time.Time{} if t.Valid is false.
Types ¶
This section is empty.