BuildColumnSchemaMap assembles a ColumnSchema map from pgx FieldDescriptions.
( fields []pgconn.FieldDescription, typeMap *pgtype.Map, customTypeMapping map[uint32]CustomDataType, )
| 71 | |
| 72 | // BuildColumnSchemaMap assembles a ColumnSchema map from pgx FieldDescriptions. |
| 73 | func BuildColumnSchemaMap( |
| 74 | fields []pgconn.FieldDescription, |
| 75 | typeMap *pgtype.Map, |
| 76 | customTypeMapping map[uint32]CustomDataType, |
| 77 | ) (map[string]ColumnSchema, error) { |
| 78 | columns := make(map[string]ColumnSchema, len(fields)) |
| 79 | for _, fd := range fields { |
| 80 | typeName, err := OIDToName(typeMap, fd.DataTypeOID, customTypeMapping) |
| 81 | if err != nil { |
| 82 | return nil, fmt.Errorf("failed to resolve type for column %s: %w", fd.Name, err) |
| 83 | } |
| 84 | columns[fd.Name] = ColumnSchema{TypeName: typeName, TypeMod: fd.TypeModifier} |
| 85 | } |
| 86 | return columns, nil |
| 87 | } |
| 88 | |
| 89 | // ColumnMapping holds a source→destination column name pair for rename resolution. |
| 90 | type ColumnMapping struct { |
no test coverage detected