code: func deleteHost(c context.Context, name string) error {
  	if name == "" {
  		return status.Error(codes.InvalidArgument, "hostname is required and must be non-empty")
  	}
  
  	db := database.Get(c)
  	res, err := db.ExecContext(c, `DELETE FROM hostnames WHERE name = ?`, name)
  	if err != nil {
  		switch e, ok := err.(*mysql.MySQLError); {
  		case !ok:
  			// Type assertion failed.
  		case e.Number == mysqlerr.ER_ROW_IS_REFERENCED_2 && strings.Contains(e.Message, "`physical_host_id`"):
  			// e.g. "Error 1452: Cannot add or update a child row: a foreign key constraint fails (FOREIGN KEY (`physical_host_id`) REFERENCES `physical_hosts` (`id`))".
  			return status.Errorf(codes.FailedPrecondition, "delete entities referencing this host first")
  		}
  		return errors.Annotate(err, "failed to delete host").Err()
  	}
  	switch rows, err := res.RowsAffected(); {
  	case err != nil:
  		return errors.Annotate(err, "failed to fetch affected rows").Err()
  	case rows == 0:
  		return status.Errorf(codes.NotFound, "host %q does not exist", name)
  	case rows == 1:
  		return nil
  	default:
  		// Shouldn't happen because name is unique in the database.
  		return errors.Reason("unexpected number of affected rows %d", rows).Err()
  	}
  }
docs: // deleteHost deletes an existing host from the database.