You are not logged in.
Pages: 1
Hello,
Imagine there are several classes in a domain:
A <- B <-C
<- D
<- E
Where D has a reference to C and E has a reference to D.
For example, how can one create a simple in-memory database? There are several issues i don't understand:
- TDDDRepositoryRestFactory.ComputeSQLRecord([C, D, E]) creates several duplicates (on all common ancestors). OK, i can remove the duplicates, but i would expect the operation to be able to identify the common ancestors.
- then TSQLRestStorageInMemory.Create takes only a single class as a parameter ???
How can the whole domain be persisted?
In a real application, there would be many domain classes, broken down in sub-domains.
FYI Environment : Lazarus/FPC 2.7.1. No Delphi environment.
Offline
Creating a complete model:
SomeModel = TSQModel.Create([Set of SQL classes]) //Not domain classes, SQL classes.
Creating the client database (as in client/server):
Client := TSQLRestClientDB.Create(ClientModel, ServerModel, ChangeFileExt(Application.ExeName,'.db3'), TSQLRestServerDB);
Populating the tables (if missing or needed to update):
TSQLRestClientDB(globalClient).Server.CreateMissingTables(0);
This works in Lazarus + FPC 2.7.1
Offline
Use TSQLRestServerFullMemory to create a simple TObjectList stored database.
http://synopse.info/files/html/Synopse% … l#TITL_138
Or use SQLITE_MEMORY_DATABASE_NAME with a SQlite3 TSQLRestServerDB/TSQLRestClientDB class.
Online
Thank you very much. I will try that.
I would suggest ComputeSQLRecord does not duplicate the code for the ancestor classes, if they are common.
Best regards,
Thierry
Offline
OK, i tried with TSQLRestServerFullMemory, using the following code in initialisation and finalisation:
Without the filename in the tableclient for class A, the database is not saved,
With the filename in the table client for class A, it is stored in its particular file, not the general file for the whole database.
What am I missing?
initialization
Database := TSQLRestServerFullMemory.Create( Model, ChangeFileExt(Application.ExeName,'.json') );
gTableA := TSQLRestStorageInMemory.Create( TSQLA, Database, ChangeFileExt(Application.ExeName,'.A.json'));
gTableB := TSQLRestStorageInMemory.Create( TSQLB, Database, ChangeFileExt(Application.ExeName,'.B.json'));
finalization
FreeAndNil(model);
FreeAndNil(gTableA);
FreeAndNil(gTableB);
Database.ExportServer;
FreeAndNil(Database);
end.
Last edited by terryc (2015-07-04 09:03:06)
Offline
Online
Thank you!
Indeed it is much simpler than I thought. The only object to create is the TSQLERestServerFullMemory. The TSQLRestStorageInMemory are not needed, as every operation can directly be performed on the RestServer.
initialization
Database := TSQLRestServerFullMemory.Create( Model, ChangeFileExt(Application.ExeName,'.json') );
finalization
FreeAndNil(model);
Database.ExportServer;
FreeAndNil(Database);
end.
and in the application layer:
objectA:= TSQLRecordA.CreateAndFillPrepare(Database, '');
...
Database.Add(objectA, true);
Last edited by terryc (2015-07-05 00:27:16)
Offline
Pages: 1