type User struct { Name string`gorm:"index"` Name2 string`gorm:"index:idx_name,unique"` Name3 string`gorm:"index:,sort:desc,collate:utf8,type:btree,length:10,where:name3 != 'jinzhu'"` Name4 string`gorm:"uniqueIndex"` Age int64`gorm:"index:,class:FULLTEXT,comment:hello \\, world,where:age > 10"` Age2 int64`gorm:"index:,expression:ABS(age)"` }
// MySQL option type User struct { Name string`gorm:"index:,class:FULLTEXT,option:WITH PARSER ngram INVISIBLE"` }
// PostgreSQL option type User struct { Name string`gorm:"index:,option:CONCURRENTLY"` }
唯一索引
标签 uniqueIndex 的工作方式类似于 index,它等同于 index:,unique
type User struct { Name1 string`gorm:"uniqueIndex"` Name2 string`gorm:"uniqueIndex:idx_name,sort:desc"` }
复合索引
对两个字段使用相同的索引名称将创建复合索引,例如
// create composite index `idx_member` with columns `name`, `number` type User struct { Name string`gorm:"index:idx_member"` Number string`gorm:"index:idx_member"` }