#1 2022-04-26 17:20:22

Stemon63
Member
Registered: 2016-10-24
Posts: 49

Mormot 2 - How to return a binary from Torm?

Hi,
I need to standardize the results from mormot, both when using queries via SQL and when using the ORM with its connection.
With queries via SQL I use an approach similar to the following to return a compact binary format to import to the client as a read-only dataset.
I use TSQLDBConnectionProperties and Sql strings.
//
function GetBin(AConnection: TSQLDBConnectionProperties; ASql: string): string;
var
stream: TStream;
begin
stream:  :=  TStringStream.Create;

AConnection.Execute(ASql, []).FetchAllToBinary(tmpStream);
stream.Seek(0, soBeginning);
result := stream.DataString;

stream.free;
end;
//
Well, it works!

How can I obtain the same result  when using TOrm with TRestServerDB as connection?


Thanks in advance!!!

Offline

#2 2022-04-26 20:21:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,242
Website

Re: Mormot 2 - How to return a binary from Torm?

Use the standard JSON serialization, for TOrm, in non-expanded format.

It won't be slower nor bigger, with proper compression over the wire, than the binary serialization.

Or you can use the binary serialization directly on the SQlite3 database instance, if you prefer - but I won't go into this direction.

Offline

Board footer

Powered by FluxBB