Loggest thy stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
567 B

3 years ago
  1. package sqltypes
  2. import (
  3. "database/sql/driver"
  4. "encoding/json"
  5. "errors"
  6. )
  7. type NullRawMessage struct {
  8. RawMessage json.RawMessage
  9. Valid bool
  10. }
  11. func (n *NullRawMessage) Scan(value interface{}) error {
  12. if value == nil {
  13. n.RawMessage, n.Valid = json.RawMessage{}, false
  14. return nil
  15. }
  16. buf, ok := value.([]byte)
  17. if !ok {
  18. return errors.New("cannot parse to bytes")
  19. }
  20. n.RawMessage, n.Valid = buf, true
  21. return nil
  22. }
  23. func (n NullRawMessage) Value() (driver.Value, error) {
  24. if !n.Valid {
  25. return nil, nil
  26. }
  27. return []byte(n.RawMessage), nil
  28. }