FetchTableColumns returns the set of column names for schema.table. If transform is non-nil, it is applied to each column name before insertion.
(ctx context.Context, q Queryer, schema, table string, style PlaceholderStyle, transform func(string) string)
| 36 | // FetchTableColumns returns the set of column names for schema.table. |
| 37 | // If transform is non-nil, it is applied to each column name before insertion. |
| 38 | func FetchTableColumns(ctx context.Context, q Queryer, schema, table string, style PlaceholderStyle, transform func(string) string) (map[string]bool, error) { |
| 39 | query, err := tableColumnsQuery(style) |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | rows, err := q.QueryContext(ctx, query, schema, table) |
| 44 | if err != nil { |
| 45 | return nil, err |
| 46 | } |
| 47 | defer func() { _ = rows.Close() }() |
| 48 | |
| 49 | cols := make(map[string]bool) |
| 50 | for rows.Next() { |
| 51 | var name string |
| 52 | if err := rows.Scan(&name); err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | if transform != nil { |
| 56 | name = transform(name) |
| 57 | } |
| 58 | cols[name] = true |
| 59 | } |
| 60 | if err := rows.Err(); err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | return cols, nil |
| 64 | } |
searching dependent graphs…