string.go 653 B

1234567891011121314151617181920212223242526272829303132
  1. package types
  2. import (
  3. "database/sql/driver"
  4. )
  5. // TextNull is an implementation of a string for the MySQL type char/varchar/text ....
  6. type TextNull string
  7. // Value implements the driver.Valuer interface,
  8. // and turns the string into a bytes for MySQL storage.
  9. func (s TextNull) Value() (driver.Value, error) {
  10. return []byte(s), nil
  11. }
  12. // Scan implements the sql.Scanner interface,
  13. // and turns the bytes incoming from MySQL into a string
  14. func (s *TextNull) Scan(src interface{}) error {
  15. if src != nil {
  16. v, ok := src.([]byte)
  17. if !ok {
  18. *s = TextNull("")
  19. return nil
  20. }
  21. *s = TextNull(v)
  22. return nil
  23. }
  24. *s = TextNull("")
  25. return nil
  26. }