Skip to content

Commit

Permalink
Add comment for pgtype.Interval struct
Browse files Browse the repository at this point in the history
Comment explicitly states that pgtype.Interval is a nullable
postgres type.
  • Loading branch information
mateuszkowalke committed Aug 22, 2024
1 parent 4f7e19d commit 98c68c2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pgtype/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ type IntervalValuer interface {
IntervalValue() (Interval, error)
}

// Interval represents an interval that may be null.
// Interval implements the [Scanner] interface so
// it can be used as a scan destination:
//
// var i Interval
// err := conn.QueryRow(context.Background(), "SELECT elapsed_time FROM foo WHERE id=$1", id).Scan(&i)
// ...
// if i.Valid {
// // use i.Days...
// } else {
// // NULL value
// }
//
// When using as a parameter for prepared statement
// the [Valid] field has to be explicitly set to [true] by the user.
type Interval struct {
Microseconds int64
Days int32
Expand Down

0 comments on commit 98c68c2

Please sign in to comment.