TODO: in the future this could theoretically be done in a single query and then the tables could be filtered in memory
(ctx context.Context, tables schema.Tables)
| 80 | |
| 81 | // TODO: in the future this could theoretically be done in a single query and then the tables could be filtered in memory |
| 82 | func (c *Client) schemaTables(ctx context.Context, tables schema.Tables) (schema.Tables, error) { |
| 83 | query := `SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND (DATABASE() IS NULL OR table_SCHEMA = DATABASE());` |
| 84 | rows, err := c.db.QueryContext(ctx, query) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | defer rows.Close() |
| 89 | schemaTables := make(schema.Tables, 0) |
| 90 | tableNames := make([]string, 0) |
| 91 | for rows.Next() { |
| 92 | var tableName string |
| 93 | |
| 94 | if err := rows.Scan(&tableName); err != nil { |
| 95 | return nil, err |
| 96 | } |
| 97 | |
| 98 | if tables.Get(tableName) == nil { |
| 99 | continue |
| 100 | } |
| 101 | tableNames = append(tableNames, tableName) |
| 102 | } |
| 103 | |
| 104 | for _, tableName := range tableNames { |
| 105 | fields, err := c.getTableColumns(ctx, tableName) |
| 106 | if err != nil { |
| 107 | return nil, err |
| 108 | } |
| 109 | schemaTables = append(schemaTables, &schema.Table{Name: tableName, Columns: fields}) |
| 110 | } |
| 111 | |
| 112 | return schemaTables, nil |
| 113 | } |
| 114 | |
| 115 | func (c *Client) addColumn(ctx context.Context, table *schema.Table, column *schema.Column) error { |
| 116 | builder := strings.Builder{} |
no test coverage detected