Search code examples
gogo-gorm

Case insensitive unique column when using gorm with sqlite driver


In my Golang application, I am using a Name column in one of my structs. I want to save the text in its original form, so for example "User1", but "user1" would be considered to be duplicate. Is this possible with gorm and sqlite driver?


Solution

  • Manually overriding the column's datatype to 'text collate nocase' worked for me, like so:

    type User struct {
        ID   int
        Name string `gorm:"index:,unique;type:text collate nocase"`
    }