SetKeys lets you specify the fields on a struct that map to primary key columns on the table. If isAutoIncr is set, result.LastInsertId() will be used after INSERT to bind the generated id to the Go struct. Automatically calls ResetSql() to ensure SQL statements are regenerated. Panics if isAutoI
(isAutoIncr bool, fieldNames ...string)
| 49 | // Panics if isAutoIncr is true, and fieldNames length != 1 |
| 50 | // |
| 51 | func (t *TableMap) SetKeys(isAutoIncr bool, fieldNames ...string) *TableMap { |
| 52 | if isAutoIncr && len(fieldNames) != 1 { |
| 53 | panic(fmt.Sprintf( |
| 54 | "gorp: SetKeys: fieldNames length must be 1 if key is auto-increment. (Saw %v fieldNames)", |
| 55 | len(fieldNames))) |
| 56 | } |
| 57 | t.keys = make([]*ColumnMap, 0) |
| 58 | for _, name := range fieldNames { |
| 59 | colmap := t.ColMap(name) |
| 60 | colmap.isPK = true |
| 61 | colmap.isAutoIncr = isAutoIncr |
| 62 | t.keys = append(t.keys, colmap) |
| 63 | } |
| 64 | t.ResetSql() |
| 65 | |
| 66 | return t |
| 67 | } |
| 68 | |
| 69 | // SetUniqueTogether lets you specify uniqueness constraints across multiple |
| 70 | // columns on the table. Each call adds an additional constraint for the |