Skip to content

[Feature Request]: Simplificar a conversão de dataset pra JSON no Storage #114

Description

@mobius1qwe

Descrição da Sugestão

Melhorar a conversão de Dataset para JSON simplificando o código existente para usar .ToJSON, com uso de classhelper para versões que suportam e outro modo mais verboso para versões que não suportam

Anexos

Hoje o código é assim:

procedure TRALApplication.DatabaseToJSON(ARequest: TRALRequest;
  AResponse: TRALResponse);
var
  query: TFDQuery;
  RALSJ: TRALStorageJSON;
  AStream: TStringStream;
begin
  query := TFDQuery.create(nil);
  RALSJ := TRALStorageJSON.Create;
  AStream := TStringStream.Create;
  try
    // faz algo com a query
    // query.blablablabla

    // converte a query para stream
    RALSJ.SaveToStream(query, AStream);

    // responde o stream
    AResponse.Answer(HTTP_OK, AStream, rctAPPLICATIONJSON);
  finally
    RALSJ.Free;
    query.Free;
  end;
end;

Modificar para algo como
Com Helper:

procedure TRALApplication.DatabaseToJSON(ARequest: TRALRequest;
  AResponse: TRALResponse);
var
  query: TFDQuery;
begin
  query := TFDQuery.create(nil);
  try
    // faz algo com a query
    // query.blablablabla

    // responde o json, versões com Helper
    AResponse.Answer(HTTP_OK, query.ToJSON, rctAPPLICATIONJSON);
  finally
    query.Free;
  end;
end;

Sem Helper:

procedure TRALApplication.DatabaseToJSON(ARequest: TRALRequest;
  AResponse: TRALResponse);
var
  query: TFDQuery;
  RALSJ: TRALStorageJSON;
begin
  query := TFDQuery.create(nil);
  RALSJ := TRALStorageJSON.Create;
  try
    // faz algo com a query
    // query.blablablabla

    // responde o json, versões sem Helper
    AResponse.Answer(HTTP_OK, RALSJ.DataSetToJSON(query), rctAPPLICATIONJSON);
  finally
    RALSJ.Free;
    query.Free;
  end;
end;

Motivo da Mudança

No response

Informações adicionais

No response

Relator do Problema

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    rev: OngoingWhen a reported issue was able to be reproduced and is currently being worked onsec: APIIssues that happen with the API feature of the packageseg: ServerIssues that happen on the Server side of the packagevcs: New FeatureWhen the issue represents a new feature for the project

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions