#2 Re: mORMot 1 » Temporary in-memory storage with TSQLRestTempStorage » 2023-04-15 20:37:58

ab wrote:

Usually we use a REST background method,  and a batch for this purpose. The batch will speed up the insertion.
It works for both mORMot 1 and mORMot 2.

What do you mean? Could you please give an example.

ab wrote:

But I may add an automated way to do it in mORMot 2, since it is a common pattern.

Good idea to have an automated way!

And could you maybe also give some answers to my questions above? Thanks smile

#3 mORMot 1 » Temporary in-memory storage with TSQLRestTempStorage » 2023-03-24 21:56:48

w0rker
Replies: 4

Hello,
I've seen TSQLRestTempStorage in the code but I'm unsure how to use it.
Right now, we use a TSQLRestClientDB with SQLite3 but we would like to write the data asynchronously into the DB from a TThread.

1. Would you recommend using TSQLRestTempStorage to speed-up writing data and reading data (99,999% of the time we need only the data from past 5min; checking if entry exist and add if not)?
2. What do we need to change in our existing code?
3. If I understood it correctly, it'll hold the old and new data in memory (RAM) and then write it from time to time into the SQLite database (based on own coded TThread with sleep time)?
4. Is this also available in mORMot2?

Thanks in advance and a nice weekend!

#4 Re: mORMot 1 » mORMot to save interface composition classes into database? » 2021-03-19 13:14:43

ab wrote:

First point is that if you use interface just to store some values, without any try..finally..free block, then use a record instead.
Interfaces were not meant for making DTO, but mostly for abstraction / SOLID code against processing classes.

Interfaces are the only way to make sure that all composition classes provide the same properties I need to access in some places in my code, no? With records I could easily forget one and then my program will crash *shrug*

  TDirInfo = record
    FDirName: String;
  end;
  TDirs = class
  private
    FDirInfo: TDirInfo;
  public
    constructor Create(...);
    function ReadDirName: String; // needed because property can't be FDirInfo.FDirName

    property DirName: String read ReadDirName;
  end;

How to reuse all this code in TFilesDirs?

And actually I'm not sending any data or so, it should just be saved to database and reloaded/be available after a restart of it.

#5 mORMot 1 » mORMot to save interface composition classes into database? » 2021-03-19 12:33:36

w0rker
Replies: 3

Hey ab,
I already use mORMot for stuff like

  TSQLNamesRecord = class(TSQLRecordNoCase)
  private
    FName: RawUTF8;
  published
    property Name: RawUTF8 read FName write FName stored AS_UNIQUE;
  end;

but I also have some classes that use composition with interfaces so e.g.

  IDirInfo = interface
  ['{10101010-1010-0101-1001-111110110110}']
    function GetDirname(): String;

    property DirName: String read GetDirname;
  end;

  IFileInfo = interface
  ['{10101010-1010-0101-1001-111110110110}']
    function GetFilename(): Integer;
    function GetFileDate(): Integer;

    property Filename: Integer read GetFilename;
    property FileDate: Integer read GetFileDate;
  end;

  // and some other interfaces

and different classes that use these interfaces (implemented as own TAggregatedObject class to reuse them by delegation) as following

  TDirs = class(TInterfacedObject, IDirInfo)
  private
    FDirInfo: IDirInfo;
  public
    constructor Create(...);

    property DirInfo: IDirInfo read FDirInfo implements IDirInfo;
  end;

  TFilesDirs = class(TInterfacedObject, IDirInfo, IFileInfo)
  private
    FDirInfo: IDirInfo;
    FFileInfo: IFileInfo;
  public
    constructor Create(...);

    property DirInfo: IDirInfo read FDirInfo implements IDirInfo;
    property FileInfo: IFileInfo read FFileInfo implements IFileInfo;
  end;

My question is now
1. how to store this info with mORMot
2. how to know if it was TDirs or TFilesDirs if I want to create the class based on my saved data

Thanks in advance!

Board footer

Powered by FluxBB