MCPcopy
hub / github.com/go-gorp/gorp / SetKeys

Method SetKeys

table.go:51–67  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

49// Panics if isAutoIncr is true, and fieldNames length != 1
50//
51func (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

Callers 15

TestCustomDateTypeFunction · 0.80
TestUIntPrimaryKeyFunction · 0.80
TestPersistentUserFunction · 0.80
TestNamedQueryMapFunction · 0.80
TestNamedQueryStructFunction · 0.80
TestOverrideVersionColFunction · 0.80
TestDoubleAddTableFunction · 0.80
TestScannerValuerFunction · 0.80
TestColumnPropsFunction · 0.80
TestWithStringPkFunction · 0.80
TestEmbeddedTimeFunction · 0.80

Calls 2

ColMapMethod · 0.95
ResetSqlMethod · 0.95

Tested by 15

TestCustomDateTypeFunction · 0.64
TestUIntPrimaryKeyFunction · 0.64
TestPersistentUserFunction · 0.64
TestNamedQueryMapFunction · 0.64
TestNamedQueryStructFunction · 0.64
TestOverrideVersionColFunction · 0.64
TestDoubleAddTableFunction · 0.64
TestScannerValuerFunction · 0.64
TestColumnPropsFunction · 0.64
TestWithStringPkFunction · 0.64
TestEmbeddedTimeFunction · 0.64