Skip to content

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

Closed

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

  1. added this to the 1.+ milestone on Sep 23, 2025
  2. added
    vcs: New FeatureWhen the issue represents a new feature for the project
    seg: ServerIssues that happen on the Server side of the package
    sec: APIIssues that happen with the API feature of the package
    rev: PlannedWhen a feature request is approved and will be implemented
    rev: OngoingWhen a reported issue was able to be reproduced and is currently being worked on
    and removed
    rev: PlannedWhen a feature request is approved and will be implemented
    on Sep 23, 2025
  3. added a commit that references this issue on Sep 29, 2025
    99b27e8
  4. modified the milestones: 1.+, 1.0 on Jun 25, 2026
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