#1 2019-05-27 12:21:01

xiwuping
Member
Registered: 2018-02-11
Posts: 32

Still confused TSQLRestClientDB versus TSQLRestServerDB

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

#2 2019-05-27 12:27:48

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

Re: Still confused TSQLRestClientDB versus TSQLRestServerDB

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

Offline

#3 2019-05-27 12:51:10

xiwuping
Member
Registered: 2018-02-11
Posts: 32

Re: Still confused TSQLRestClientDB versus TSQLRestServerDB

ab wrote:

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

#4 2019-05-27 13:29:10

greedy
Member
Registered: 2018-10-26
Posts: 11

Re: Still confused TSQLRestClientDB versus TSQLRestServerDB

ab wrote:

- almost never TSQLRestClientDB, which is just an encapsulation of TSQLRestServerDB

PROJECT DOCUMENTATION wrote:

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).

https://synopse.info/files/html/Synopse … l#TITL_186

Offline

#5 2019-05-27 13:33:52

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

Re: Still confused TSQLRestClientDB versus TSQLRestServerDB

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 !

Offline

Board footer

Powered by FluxBB