A Postgres uuid[] field for gorm.io
go get github.com/ubgo/gormuuid
type User struct {
TagIDs gormuuid.UUIDArray `gorm:"type:uuid[]"` // Column will take {} as default
}
var tagIds gormuuid.UUIDArray = []uuid.UUID{uuid.New(), uuid.New()}
db.Create(&User{
TagIDs: tagIds,
})
var users []User
tagId, _ := uuid.Parse("c4ba81a1-9e57-4e60-b811-2860136ab803")
db.Model(&User{}).Where("tag_ids && ?", pq.Array([]uuid.UUID{tagId})).Find(&users)
If you would like to contribute to the project, please fork it and send us a pull request. Please add tests for any new features or bug fixes.
- Author - Aman Khanakia
- Website - https://khanakia.com
goutil is MIT licensed.