#1 2024-03-29 05:53:52

slapshot
Member
Registered: 2020-01-21
Posts: 17

Object lists

Hello, sometimes can be useful having a list of object loaded in ram, something such as TList or TObjectList class. I wonder if there Is such a Mormot 2 specialized class you can advice. I'm a bit lost into documentation.

Thank you

Offline

#2 2024-03-29 08:51:13

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

Re: Object lists

With modern pascal, you can use mormot.core.collections.pas and its IList<> storage.
It encapsulates TSynDictionary and TDynArrayHashed non-generics functions from mormot.core.json.pas.
They support a lot of features, up to JSON or binary serialization.

Otherwise, you have TSynList / TSynObjectList and TRawUtf8List (with its Objects[] property) to store such items in mormot.core.data.pas.

But perhaps the more "mormotish" low-level way of storing data in RAM is to use a dynamic array, and TDynArrayHashed.

If you are lost in the framework, take a look at the README files in the repository, or at the sum-up at the beginning of every unit.
It makes a simple and clear list of the features included by each very unit.

Offline

#3 2024-03-29 10:40:34

flydev
Member
From: France
Registered: 2020-11-27
Posts: 73
Website

Re: Object lists

Take this simple example to get started.

type
  TOrmMyObject = class(TOrm)
    FTitle: : RawUtf8;
    FStatus: int32;
  published
    property Title: RawUtf8 read FTitle write FTitle;
    property Status: int32 read FStatus write FStatus;
  end;

// ...

procedure GetIList;
var 
  list: IList<TOrmMyObject>;
  obj: TOrmMyObject;
begin
  if FHttpClient.Client.Orm.RetrieveIList(TOrmMyObject, list, 'ID,status,title') then
  begin
    ConsoleWrite('retrieved % objects', [list.count]);
    for obj in list do
      ConsoleWrite('Obj ID %: title=%, status=%', [obj.ID, obj.title, obj.status]);
  end;
end;

A note about finding features in mormot, when I started with mormot I was used to go in the v1 documentation and using text search to find keywords; You can apply the same flow with the source-code which is nice commented, eg. in the mormot/src folder, just use a tool to search keyword in *.pas files. You will find also a lot of implementation infos by reading the test code from the mormot2/test folder. You can also keep the v1 source code at hand to get more samples adapting them to pure mormot2.

Clipboard-03-29-2024-01.jpg

v1 doc: https://synopse.info/files/html/Synopse … l#TITLE_81
source: https://github.com/synopse/mORMot2/blob … ctions.pas

Hope it help.

Offline

#4 2024-03-29 12:48:28

slapshot
Member
Registered: 2020-01-21
Posts: 17

Re: Object lists

Thanks for the suggestions, guys ! I've been away from programming for so long, and I'm trying to rebuild everything a little bit. Not that I was a great programmer 20 years ago and in fact my wonder is in considering the effort to understand this framework and the idea that it could have been written with such mastery amazes me, really a lot of stuff for this gem of a framework, congratulations.
For this server project of mine the choice was between learning another development environment or brushing up on my reminiscences of Object Pascal which I have always loved, and with the presence of Mormot 2 my choice fell on the latter.
BTW, I will have to write a daemon on a linux vm that queries a rest api server (probably triangulating another rest api server as well), then expose a series of interfaces to allow desktop, browser and mobile applications to talk to the server itself. I think it will not be easy, I am still in the design phase and then testing a small part of the framework. I hope to succeed in this endeavor.

Offline

Board footer

Powered by FluxBB