DropCast drops an existing cast.
(ctx context.Context, castIDs ...id.Cast)
| 466 | |
| 467 | // DropCast drops an existing cast. |
| 468 | func (pgc *Collection) DropCast(ctx context.Context, castIDs ...id.Cast) error { |
| 469 | if len(castIDs) == 0 { |
| 470 | return nil |
| 471 | } |
| 472 | // Check that each name exists before performing any deletions |
| 473 | for _, castID := range castIDs { |
| 474 | if _, ok := builtInCasts[castID]; ok { |
| 475 | return errors.Errorf(`cannot delete built-in cast from type %s to type %s`, |
| 476 | castID.SourceType().TypeName(), castID.TargetType().TypeName()) |
| 477 | } |
| 478 | if ok, err := pgc.underlyingMap.Has(ctx, string(castID)); err != nil { |
| 479 | return err |
| 480 | } else if !ok { |
| 481 | return errors.Errorf(`cast from type %s to type %s does not exist`, |
| 482 | castID.SourceType().TypeName(), castID.TargetType().TypeName()) |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | // Now we'll remove the casts from the map |
| 487 | mapEditor := pgc.underlyingMap.Editor() |
| 488 | for _, castID := range castIDs { |
| 489 | err := mapEditor.Delete(ctx, string(castID)) |
| 490 | if err != nil { |
| 491 | return err |
| 492 | } |
| 493 | } |
| 494 | newMap, err := mapEditor.Flush(ctx) |
| 495 | if err != nil { |
| 496 | return err |
| 497 | } |
| 498 | pgc.underlyingMap = newMap |
| 499 | pgc.mapHash = pgc.underlyingMap.HashOf() |
| 500 | return nil |
| 501 | } |
| 502 | |
| 503 | // resolveName returns the fully resolved name of the given cast. Returns an error if the name is ambiguous. |
| 504 | func (pgc *Collection) resolveName(ctx context.Context, schemaName string, formattedName string) (id.Cast, error) { |
no test coverage detected