MCPcopy Index your code
hub / github.com/Masterminds/structable / primaryKeyField

Function primaryKeyField

schema2struct/schema2struct.go:223–242  ·  view source on GitHub ↗
(tbl string, b squirrel.StatementBuilderType)

Source from the content-addressed store, hash-verified

221}
222
223func primaryKeyField(tbl string, b squirrel.StatementBuilderType) ([]string, error) {
224 q := b.Select("column_name").
225 From("INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c").
226 LeftJoin("INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t USING(constraint_name)").
227 Where("t.table_name = ? AND t.constraint_type = 'PRIMARY KEY'", tbl).
228 OrderBy("ordinal_position")
229
230 rows, err := q.Query()
231 if err != nil {
232 return []string{}, err
233 }
234
235 res := []string{}
236 for rows.Next() {
237 var s string
238 rows.Scan(&s)
239 res = append(res, s)
240 }
241 return res, nil
242}
243
244func sequentialKey(tbl, pk string, b squirrel.StatementBuilderType) bool {
245

Callers 1

importTableFunction · 0.85

Calls 2

QueryMethod · 0.80
ScanMethod · 0.80

Tested by

no test coverage detected