GetPrimaryKeyColumns gets all primary columns in ordinal order
(tctx *tcontext.Context, db *BaseConn, database, table string)
| 640 | |
| 641 | // GetPrimaryKeyColumns gets all primary columns in ordinal order |
| 642 | func GetPrimaryKeyColumns(tctx *tcontext.Context, db *BaseConn, database, table string) ([]string, error) { |
| 643 | priKeyColsQuery := fmt.Sprintf("SHOW INDEX FROM `%s`.`%s`", escapeString(database), escapeString(table)) |
| 644 | results, err := db.QuerySQLWithColumns(tctx, []string{"KEY_NAME", "COLUMN_NAME"}, priKeyColsQuery) |
| 645 | if err != nil { |
| 646 | return nil, err |
| 647 | } |
| 648 | |
| 649 | cols := make([]string, 0, len(results)) |
| 650 | for _, oneRow := range results { |
| 651 | keyName, columnName := oneRow[0], oneRow[1] |
| 652 | if keyName == "PRIMARY" { |
| 653 | cols = append(cols, columnName) |
| 654 | } |
| 655 | } |
| 656 | return cols, nil |
| 657 | } |
| 658 | |
| 659 | // getNumericIndex picks up indices according to the following priority: |
| 660 | // primary key > unique key with the smallest count > key with the max cardinality |
no test coverage detected