AddIndex registers the index with gorp for specified table with given parameters. This operation is idempotent. If index is already mapped, the existing *IndexMap is returned Function will panic if one of the given for index columns does not exists Automatically calls ResetSql() to ensure SQL state
(name string, idxtype string, columns []string)
| 137 | // Automatically calls ResetSql() to ensure SQL statements are regenerated. |
| 138 | // |
| 139 | func (t *TableMap) AddIndex(name string, idxtype string, columns []string) *IndexMap { |
| 140 | // check if we have a index with this name already |
| 141 | for _, idx := range t.indexes { |
| 142 | if idx.IndexName == name { |
| 143 | return idx |
| 144 | } |
| 145 | } |
| 146 | for _, icol := range columns { |
| 147 | if res := t.ColMap(icol); res == nil { |
| 148 | e := fmt.Sprintf("No ColumnName in table %s to create index on", t.TableName) |
| 149 | panic(e) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | idx := &IndexMap{IndexName: name, Unique: false, IndexType: idxtype, columns: columns} |
| 154 | t.indexes = append(t.indexes, idx) |
| 155 | t.ResetSql() |
| 156 | return idx |
| 157 | } |
| 158 | |
| 159 | // SetVersionCol sets the column to use as the Version field. By default |
| 160 | // the "Version" field is used. Returns the column found, or panics |