1

I'm implementing a Gorm model to access a table in MySQL.
It is something like this:

import (
    "time"
)

type MyModel struct {

  // ...some attributes...

  CreatedAt time.Time
  UpdatedAt time.Time
  DeletedAt *time.Time
}

I am wondering if it is clear enough to follow Gorm conventions about using a pointer to time.Time to point (;)) out this attribute could be nil, or it is better to use database/sql/NullTime.

Do you think of any other benefit to use NullTime apart from readability?

germanio
  • 861
  • 1
  • 17
  • 27

1 Answers1

1

With NullTime you do not need to do nil checks everywhere to avoid panic.

Also, some other db libraries use null conversion wrappers: sqlboiler, dbr, sqlc, and db-related services in the AWS sdk

brietsparks
  • 4,776
  • 8
  • 35
  • 69