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?
Asked
Active
Viewed 274 times
1
-
Does this answer your question? [How to make a case-insensitive unique column in SQLite](https://stackoverflow.com/questions/20914946/how-to-make-a-case-insensitive-unique-column-in-sqlite) – some-user Oct 25 '22 at 08:58
-
1This isn't really a matter of your Go libraries but of your MySQL collation. Configure your table in a manner that the `name` column has a case insensitive collation, e.g. `utf8mb4_unicode_ci` (the "`_ci`" suffix tells that it's case insensitive). – NotX Oct 25 '22 at 12:14
1 Answers
1
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"`
}

SentientSeven
- 26
- 3