nulltime_legacy.go 871 B

12345678910111213141516171819202122232425262728293031323334
  1. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
  2. //
  3. // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public
  6. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  7. // You can obtain one at http://mozilla.org/MPL/2.0/.
  8. // +build !go1.13
  9. package mysql
  10. import (
  11. "time"
  12. )
  13. // NullTime represents a time.Time that may be NULL.
  14. // NullTime implements the Scanner interface so
  15. // it can be used as a scan destination:
  16. //
  17. // var nt NullTime
  18. // err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
  19. // ...
  20. // if nt.Valid {
  21. // // use nt.Time
  22. // } else {
  23. // // NULL value
  24. // }
  25. //
  26. // This NullTime implementation is not driver-specific
  27. type NullTime struct {
  28. Time time.Time
  29. Valid bool // Valid is true if Time is not NULL
  30. }