Helper to sort a given map of tables with a second list giving a priority. If an element is present in the input and the priority lists, the item will appear first (in the order of the priority list), all other items appear in the order given in the input
(priorityList []string)
| 352 | // appear first (in the order of the priority list), all other items appear in |
| 353 | // the order given in the input |
| 354 | func (c TableSchemaCache) GetTableListWithPriority(priorityList []string) (prioritizedTableNames []string) { |
| 355 | // just a fast lookup if the list contains items already |
| 356 | contains := map[string]struct{}{} |
| 357 | if len(priorityList) >= 0 { |
| 358 | for _, tableName := range priorityList { |
| 359 | // ignore tables given in the priority list that we don't know |
| 360 | if _, found := c[tableName]; found { |
| 361 | contains[tableName] = struct{}{} |
| 362 | prioritizedTableNames = append(prioritizedTableNames, tableName) |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | for tableName, _ := range c { |
| 367 | if _, found := contains[tableName]; !found { |
| 368 | prioritizedTableNames = append(prioritizedTableNames, tableName) |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | return |
| 373 | } |
| 374 | |
| 375 | func showDatabases(c *sql.DB) ([]string, error) { |
| 376 | rows, err := c.Query("show databases") |
no outgoing calls