#1 2017-08-24 08:20:16

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Idea - TSQLRecord keep a reference of TSQLRest

Hi,

It would be a nice idea to put a reference of client TSQLRest inside a TSQLRecord because lazy loading of public properties on runtime.

Imagine the next scenario :

TMe = class(TSQLRecord)
private
  ffriendcount : Integer;
  frestinstance : TSQLRest;
public
  property FriendCount : Integer read ffriendcount;
  function FillOne: boolean;
published
  property Name : RawUTF8 read fname write fname;
end;

function TMe.FillOne : Boolean
begin
  result := Inherited;
  if result then frestinstance.OneFieldValue(TFriends, 'COUNT(*)', 'ISMyFriend=?', [], [True], ffriendcount);
end;

When call Constructor (CreateAndFillPrepare) keep the SQLRest instance.

What do you think?

Offline

#2 2017-08-24 08:48:19

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

Re: Idea - TSQLRecord keep a reference of TSQLRest

One of the goals was to reduce the memory load of each TSQLRecord, since there may be a lot of instances created.
The TSQLRecord has only reference to what is needed.

Another idea is that a TSQLRecord is some kind of abstract entity, containing the values of an aggregate.
Another problem with your approach is that you put your queries within the TSQLRecord, whereas they should rather be written in a separated persistence service, to follow the separation of concern pattern.
Principle is to have TSQLRecord methods providing some process at aggregate level, without any dependency (e.g. check for valid or missing fields, do some basic computation using the aggregate values).
Then let all persistence be done in a service, depending on the database.

In business code, it is pretty common to switch from one TSQLRest to another, e.g. if you copy values.
In this case, an embedded TSQLRest would be confusing.

Last but not least (and linked to the previous items), this it is an entity object, you may send a TSQLRecord over the wire, in SOA interface services.
And in this case, you will loose the TSQLRest instance context, which is local to the server only.

So it doesn't seem as a nice idea to me...

Offline

#3 2017-08-24 09:20:42

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: Idea - TSQLRecord keep a reference of TSQLRest

Thanks Arnaud I appreciate your fast response

I will use another pattern/method to populate non persistent values.

Offline

Board footer

Powered by FluxBB