#1 2022-04-14 13:44:40

rdevine
Member
Registered: 2014-02-20
Posts: 52

TRestStorageInMemory usage

I'm starting to work my way through the various demos - am preparing to build my first real mORMot system so trying to understand the basics. Also comparing v1 and v2 and will be using the latter for my system.

Demo 1 in v1 (In Memory ORM): Uses TSQLRestStorageInMemory - Data is written as JSON to a text file. Easy to understand although have seen mention by AB in a couple of forum threads that TSQLRestStorageInMemory shouldn't be used "stand-alone".

Demo 1 in v2 (Martin Doyle): Uses TRestClientDB. Data is written to a SQLite database file.

Modify Demo 1 in v2: Use TRestServerFullMemory. Data is now written as JSON to a text file. Found a reference in the forum by AB (thread 34049) that T(SQL)RestServerFullMemory has a full REST process included so is slower than TSQLRestStorageInMemory/TRestStorageInMemory.

Modify Demo 1 in v2: Use TRestStorageInMemory. Examining the v2 code, there's no simple alias for TSQLRestStorageInMemory/TRestStorageInMemory and the implementation has changed. I get an AV when attempting to add a record.

So my question is - should TRestStorageInMemory never be used stand-alone? I've seen the test code where an instance is extracted from a TRestServerDB subclass, and also forum thread 36294 which does something similar. Is this the only way TRestStorageInMemory should ever be used?

Thanks, Bob

Offline

#2 2022-04-14 15:28:07

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

Re: TRestStorageInMemory usage

TRestStorageInMemory is not really slower than TRestServerFullMemory. The REST routing is only of a small impact.
The main criteria is not about performance, but about usability: TRestStorage classes are at ORM class level, whereas TRestServer is at REST level. So TRestServer hosts both ORM and SOA features, and can be published via HTTP or other means.

So, for instance, TRestServerFullMemory is perfect to host public API services with no database.
Then you use TRestServerDB inside the service implementations, ideally as a persistence service, implemented in the DDD infrastructure layer.

TRestStorageInMemory can be used mainly:
- from TRestServerFullMemory, in which all ORM classes are stored as TRestStorageInMemory
- from TRestServerDB, in which you specify a given ORM class to be stored as TRestStorageInMemory
- but you could use it stand-alone, if you want to maintain some kind of list of ORM classes, in memory, with more features than a plain list (e.g. indexes, or basic SQL execution)
- in all cases above, when direct access to the array of TOrm instances make sense, for low-level code.

Offline

#3 2022-04-14 16:08:06

rdevine
Member
Registered: 2014-02-20
Posts: 52

Re: TRestStorageInMemory usage

That's very clear - thank you. I must be messing something up with my stand-alone test - will investigate further.

Offline

#4 2022-04-14 23:44:16

rdevine
Member
Registered: 2014-02-20
Posts: 52

Re: TRestStorageInMemory usage

The AV is caused by specifying nil for the server in the TRestStorageInMemory constructor. In v1 I can use nil in the TSQLTestStorageInMemory but in v2 the nil fRest in the base TRestOrm eventually gets used in TRestOrm.GetServerTimestamp (via TOrm.ComputeFieldsBeforeWrite).

Offline

Board footer

Powered by FluxBB