Last active
September 23, 2024 21:50
-
-
Save raelb/c7633d47575abadd3b787aa91902ee30 to your computer and use it in GitHub Desktop.
mormot service method returns base64 string on Lazarus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
TNotebook = packed record | |
ID: TID; | |
Title: RawUTF8; | |
GUID: RawUTF8; | |
CurrentNote: TID; | |
procedure LoadFromObj(OrmNotebook: TOrmNotebook); | |
end; | |
TNotebookArray = array of TNotebook; | |
function TNotebookService.List(var Notebooks: TNotebookArray): | |
TServiceCustomStatus; | |
var | |
i: Integer; | |
Results: TObjectList; | |
begin | |
Result := HTTP_SUCCESS; | |
Results := Self.Server.Orm.RetrieveList(TOrmNotebook, | |
'UserId = ?', [GetUserId], ''); | |
try | |
if Results <> nil then | |
begin | |
for i := 0 to Results.Count - 1 do | |
begin | |
SetLength(Notebooks, Length(Notebooks) + 1); | |
Notebooks[I].LoadFromObj(Results[i] as TOrmNotebook); | |
end; | |
end; | |
finally | |
if Results <> nil then | |
Results.Free; | |
end; | |
end; | |
// Similar results with below method on the Server: | |
procedure TSampleServer.ListNotebooks(Ctxt: TSQLRestServerURIContext); | |
var | |
Json: RawUTF8; | |
Notebooks: TNotebookArray; | |
begin | |
GetNotebooks(Notebooks); | |
Json := DynArraySaveJson(Notebooks, TypeInfo(TNotebookArray)); | |
Ctxt.Returns(Json); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment