Source File
binuuid.go
Belonging Package
gorm.io/datatypes
package datatypesimport ()// This datatype is similar to datatypes.UUID, major difference being that// this datatype stores the uuid in the database as a binary (byte) array// instead of a string. Developers may use either as per their preference.type BinUUID uuid.UUID// NewBinUUIDv1 generates a uuid version 1, panics on generation failure.func () BinUUID {return BinUUID(uuid.Must(uuid.NewUUID()))}// NewBinUUIDv4 generates a uuid version 4, panics on generation failure.func () BinUUID {return BinUUID(uuid.Must(uuid.NewRandom()))}// NewNilBinUUID generates a nil uuid.func () BinUUID {return BinUUID(uuid.Nil)}// BinUUIDFromString returns the BinUUID representation of the specified uuidStr.func ( string) BinUUID {return BinUUID(uuid.MustParse())}// GormDataType gorm common data type.func (BinUUID) () string {return "BINARY(16)"}// GormDBDataType gorm db data type.func (BinUUID) ( *gorm.DB, *schema.Field) string {switch .Dialector.Name() {case "mysql":return "BINARY(16)"case "postgres":return "BYTEA"case "sqlserver":return "BINARY(16)"case "sqlite":return "BLOB"default:return ""}}// Scan is the scanner function for this datatype.func ( *BinUUID) ( interface{}) error {, := .([]byte)if ! {return errors.New("unable to convert value to bytes")}, := uuid.FromBytes()if != nil {return}* = BinUUID()return nil}// Value is the valuer function for this datatype.func ( BinUUID) () (driver.Value, error) {return uuid.UUID().MarshalBinary()}// String returns the string form of the UUID.func ( BinUUID) () []byte {, := uuid.UUID().MarshalBinary()if != nil {return nil}return}// String returns the string form of the UUID.func ( BinUUID) () string {return uuid.UUID().String()}// Equals returns true if bytes form of BinUUID matches other, false otherwise.func ( BinUUID) ( BinUUID) bool {return bytes.Equal(.Bytes(), .Bytes())}// Length returns the number of characters in string form of UUID.func ( BinUUID) () int {return len(.Bytes())}// Length returns the number of characters in string form of UUID.func ( BinUUID) () int {return len(.String())}// IsNil returns true if the BinUUID is nil uuid (all zeroes), false otherwise.func ( BinUUID) () bool {return uuid.UUID() == uuid.Nil}// IsEmpty returns true if BinUUID is nil uuid or of zero length, false otherwise.func ( BinUUID) () bool {return .IsNil() || .Length() == 0}// IsNilPtr returns true if caller BinUUID ptr is nil, false otherwise.func ( *BinUUID) () bool {return == nil}// IsEmptyPtr returns true if caller BinUUID ptr is nil or it's value is empty.func ( *BinUUID) () bool {return .IsNilPtr() || .IsEmpty()}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |