diff options
Diffstat (limited to '')
-rw-r--r-- | pkg/types/uuid.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pkg/types/uuid.go b/pkg/types/uuid.go new file mode 100644 index 0000000..02acbcd --- /dev/null +++ b/pkg/types/uuid.go @@ -0,0 +1,24 @@ +package types + +import ( + "database/sql/driver" + "encoding" + "github.com/google/uuid" +) + +// UUID is like uuid.UUID, but marshals itself binarily (not like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) in SQL context. +type UUID struct { + uuid.UUID +} + +// Value implements driver.Valuer. +func (uuid UUID) Value() (driver.Value, error) { + return uuid.UUID[:], nil +} + +// Assert interface compliance. +var ( + _ encoding.TextUnmarshaler = (*UUID)(nil) + _ driver.Valuer = UUID{} + _ driver.Valuer = (*UUID)(nil) +) |