I'm working with existing MSSQL Server DB, it already has entries and now we are integrating GORM to the existent Go project. Before GORM, this tool used to work with this package github.com/denisenkom/go-mssqldb so we use it's uuid integrated driver, now following the GORM examples, we decided to use the google/uuid package.
But now, the uuid.UUID handle in different way the MSSQL uuid's, why is this happening?
Using google pkg:
type User struct {
ID uuid.UUID `json:"id" gorm:"primaryKey;column:id;type:uuid"
sql:"type:uuid"`
XID int `json:"x_id" gorm:"column:x_id;type:int`
}
x := 1
usr := User{}
db.Model(&User{}).
Where("x_id = ?", x).
First(&usr)
// ID -> 3913a9d1-9c08-3f4c-b816-f55c899f5617
Using Denisen pkg:
type User struct {
ID mssql.UniqueIdentifier `json:"id" gorm:"primaryKey;column:id;type:uuid"
sql:"type:uuid"`
XID int `json:"x_id" gorm:"column:x_id;type:int`
}
x := 1
usr := User{}
db.Model(&User{}).
Where("x_id = ?", x).
First(&usr)
// ID -> D1A91339-089C-4C3F-B816-F55C899F5617
Actually, if I make the raw SELECT in my MSSQL client the result is equal to Denisen pkg, please take a look the last 2 blocks of the google's uuid are the same but lower cased, the another ones are the same letters/numbers but in different places and lower cased.
Should I use some kind of configuration to use the google uuid package?
I don't want to use the Denisen pkg because it imports the full package and I just need the uuid section, and google uuid includes the scanner interfase to use with sql.
Any help??
Tks!