(field *Field)
| 97 | } |
| 98 | |
| 99 | func parseFieldIndexes(field *Field) (indexes []Index, err error) { |
| 100 | for _, value := range strings.Split(field.Tag.Get("gorm"), ";") { |
| 101 | if value != "" { |
| 102 | v := strings.Split(value, ":") |
| 103 | k := strings.TrimSpace(strings.ToUpper(v[0])) |
| 104 | if k == "INDEX" || k == "UNIQUEINDEX" { |
| 105 | var ( |
| 106 | name string |
| 107 | tag = strings.Join(v[1:], ":") |
| 108 | idx = strings.IndexByte(tag, ',') |
| 109 | tagSetting = strings.Join(strings.Split(tag, ",")[1:], ",") |
| 110 | settings = ParseTagSetting(tagSetting, ",") |
| 111 | length, _ = strconv.Atoi(settings["LENGTH"]) |
| 112 | ) |
| 113 | |
| 114 | if idx == -1 { |
| 115 | idx = len(tag) |
| 116 | } |
| 117 | |
| 118 | name = tag[0:idx] |
| 119 | if name == "" { |
| 120 | subName := field.Name |
| 121 | const key = "COMPOSITE" |
| 122 | if composite, found := settings[key]; found { |
| 123 | if len(composite) == 0 || composite == key { |
| 124 | err = fmt.Errorf( |
| 125 | "the composite tag of %s.%s cannot be empty", |
| 126 | field.Schema.Name, |
| 127 | field.Name) |
| 128 | return |
| 129 | } |
| 130 | subName = composite |
| 131 | } |
| 132 | name = field.Schema.namer.IndexName( |
| 133 | field.Schema.Table, subName) |
| 134 | } |
| 135 | |
| 136 | if (k == "UNIQUEINDEX") || settings["UNIQUE"] != "" { |
| 137 | settings["CLASS"] = "UNIQUE" |
| 138 | } |
| 139 | |
| 140 | priority, err := strconv.Atoi(settings["PRIORITY"]) |
| 141 | if err != nil { |
| 142 | priority = 10 |
| 143 | } |
| 144 | |
| 145 | indexes = append(indexes, Index{ |
| 146 | Name: name, |
| 147 | Class: settings["CLASS"], |
| 148 | Type: settings["TYPE"], |
| 149 | Where: settings["WHERE"], |
| 150 | Comment: settings["COMMENT"], |
| 151 | Option: settings["OPTION"], |
| 152 | Fields: []IndexOption{{ |
| 153 | Field: field, |
| 154 | Expression: settings["EXPRESSION"], |
| 155 | Sort: settings["SORT"], |
| 156 | Collate: settings["COLLATE"], |
no test coverage detected