You are not logged in.
Across the various mORMot official samples, Erick Engelke book, and some online blogs (such as this very good one: https://medium.com/@step.bester/the-orm … 11c8ac0c35), I see sometimes people use TSQLRestServerDB directly to do the ORM actions, sometimes they use TSQLRestClientDB, and sometimes TSQLRestClient
Forgive my dumb question - what is the use case for each of these?
When should I -
- Use TSQLRestServerDB?
- Use TSQLRestClientDB?
- Use TSQLRestClient?
Any advice is appreciated. Still on the learning curve.
Last edited by xiwuping (2019-05-27 12:52:46)
Offline
TSQLRestClientDB is when your code requires explicitly a TSQLRestClient descendant.
This is the case for some samples, but not very realistic.
But it is not mandatory, and using TSQLRestServer and a TSQLRest variable should be enough for most of the cases.
Usually, I use as variables/fields (using the constructor of the actual class):
- TSQLRest if possible (more abstract definition)
- TSQLRestClient for client side (and the proper connection class)
- TSQLRestServer or TSQLRestServerDB when direct access to the DB or the services is required
- almost never TSQLRestClientDB, which is just an encapsulation of TSQLRestServerDB
Online
TSQLRestClientDB is when your code requires explicitly a TSQLRestClient descendant.
This is the case for some samples, but not very realistic.
But it is not mandatory, and using TSQLRestServer and a TSQLRest variable should be enough for most of the cases.Usually, I use as variables/fields (using the constructor of the actual class):
- TSQLRest if possible (more abstract definition)
- TSQLRestClient for client side (and the proper connection class)
- TSQLRestServer or TSQLRestServerDB when direct access to the DB or the services is required
- almost never TSQLRestClientDB, which is just an encapsulation of TSQLRestServerDB
I would like to have both the Server, and Client in the same process, thus in the following code, which client class had I best use?
var
client: TSQLRest;
server: TSQLRestServerDB;
model: TSQLModel;
begin
model := TSQLModel.Create([TSQLAuthUser, TSQLAuthGroup]);
server := TSQLRestServerDB.Create(model, 'test.db3', False);
client := ?.Create() // Which proper client class should I use?
... ...
end;
Last edited by xiwuping (2019-05-27 12:57:47)
Offline
- almost never TSQLRestClientDB, which is just an encapsulation of TSQLRestServerDB
For a stand-alone application, create a TSQLRestClientDB. This particular class will initialize an internal TSQLRestServerDB instance, and you'll have full access to the SQLite3 database in the same process, with no speed penalty.
Content will still be converted to and from JSON, but there will be no delay due to the transmission of the data. Having JSON at hand will enable internal cache - see below - and allow to combine this in-process direct process with other transmission protocols (like named pipes or HTTP).
Offline
If client is a TSQLRest, then no need to create some instance, just use directly the TSQLRestServerDB, which inherit from TSQLRest:
var client: TSQLRest;
server: TSQLRestServerDB;
...
client := server;
and, of course, don't call client.Free !
Online