GetQueryHistory gets a single query history. Query histories are private to their creator, so only the creator may retrieve one.
(ctx context.Context, req *connect.Request[v1pb.GetQueryHistoryRequest])
| 1467 | // GetQueryHistory gets a single query history. Query histories are private to |
| 1468 | // their creator, so only the creator may retrieve one. |
| 1469 | func (s *SQLService) GetQueryHistory(ctx context.Context, req *connect.Request[v1pb.GetQueryHistoryRequest]) (*connect.Response[v1pb.QueryHistory], error) { |
| 1470 | user, ok := GetUserFromContext(ctx) |
| 1471 | if !ok { |
| 1472 | return nil, connect.NewError(connect.CodeInternal, errors.Errorf("user not found")) |
| 1473 | } |
| 1474 | |
| 1475 | projectID, historyID, err := common.GetProjectIDQueryHistoryID(req.Msg.Name) |
| 1476 | if err != nil { |
| 1477 | return nil, connect.NewError(connect.CodeInvalidArgument, err) |
| 1478 | } |
| 1479 | |
| 1480 | history, err := s.store.GetQueryHistory(ctx, historyID) |
| 1481 | if err != nil { |
| 1482 | return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to get query history: %v", err.Error())) |
| 1483 | } |
| 1484 | // Hide existence from non-creators and project mismatches by returning the |
| 1485 | // same not-found error for all three cases. |
| 1486 | if history == nil || history.Project != projectID || history.Creator != user.Email { |
| 1487 | return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("query history %q not found", req.Msg.Name)) |
| 1488 | } |
| 1489 | |
| 1490 | queryHistory, err := s.convertToV1QueryHistory(ctx, history) |
| 1491 | if err != nil { |
| 1492 | return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to convert query history")) |
| 1493 | } |
| 1494 | return connect.NewResponse(queryHistory), nil |
| 1495 | } |
| 1496 | |
| 1497 | // The Build*Func parser-context helpers moved to |
| 1498 | // `backend/component/parsercontext` so the runner layer can use them |
nothing calls this directly
no test coverage detected