Example #1
0
    def aql(self, request, name: str):
        """Execute AQL in a workspace."""
        serializer = AqlQuerySerializer(data=request.query_params)
        serializer.is_valid(raise_exception=True)
        query_str = serializer.validated_data['query']
        workspace: Workspace = get_object_or_404(Workspace, name=name)
        database = workspace.get_arango_db()
        query = ArangoQuery(database, query_str)

        try:
            cursor: Cursor = query.execute()
            return Response(
                cursor,
                status=status.HTTP_200_OK,
            )
        except AQLQueryExecuteError as err:
            # Invalid query, time/memory limit reached, or
            # attempt to run a mutating query as the readonly user
            return Response(
                err.error_message,
                status=status.HTTP_400_BAD_REQUEST,
            )
        except ArangoServerError as err:
            # Arango server errors unrelated to the client's query
            return Response(err.error_message,
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Example #2
0
def execute_query(task_id: int) -> None:
    query_task: AqlQuery = AqlQuery.objects.select_related('workspace').get(id=task_id)
    workspace: Workspace = query_task.workspace
    query_str = query_task.query
    # Run the query on Arango DB
    database = workspace.get_arango_db()
    query = ArangoQuery(database, query_str, time_limit_secs=60)
    cursor: Cursor = query.execute()

    # Store the results on the task object
    query_task.results = list(cursor)
    query_task.save()