26 lines
440 B
Go
26 lines
440 B
Go
package database
|
|
|
|
import (
|
|
"github.com/jackc/pgtype"
|
|
|
|
"dev.tandem.ws/tandem/camper/pkg/uuid"
|
|
)
|
|
|
|
type ZeroNullUUID string
|
|
|
|
func (src ZeroNullUUID) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error) {
|
|
if src == "" {
|
|
return nil, nil
|
|
}
|
|
|
|
bytes, err := uuid.Parse(string(src))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
nullable := pgtype.UUID{
|
|
Bytes: bytes,
|
|
Status: pgtype.Present,
|
|
}
|
|
return nullable.EncodeBinary(ci, buf)
|
|
}
|