You are not logged in.
I am learning, since TSQLHttpServer can have multiple TSQLRestServerDB, a TSQLRestServerDB can only has a TSQLMode, so if we have two or more TSQLRestServerDB, how can we use the Same TAuthUser and TAuthGroup?
function CreateModel: TSQLModel;
begin
result := TSQLModel.Create([TSQLAuthGroup, TSQLAuthUser, TSQLTest], 'root');
end;
function CreateModel2: TSQLModel;
begin
result := TSQLModel.Create([TSQLAuthGroup, TSQLAuthUser, TSQLTest2], 'root2');
end;
or make a sub class of TSQLAuthGroup and TSQLAuthUser like this:
function CreateModel2: TSQLModel;
begin
result := TSQLModel.Create([TSQLAuthGroup2, TSQLAuthUser2, TSQLTest2], 'root2');
end;
this method a same user will need two entry, if more model, then more user entry, is there some method only has one entry for a user, the import thing is the AuthGroup's AccessRights, is it can set more than one Model's privilege? thanks!
Offline
Accessing the same SQLite3 database from several TSQLRestServerDB is not a good idea, by design of the SQLite3 engine itself, which is followed by mORMot.
You can safely access external tables (e.g. in Oracle/PostgreSQL....) with several TSQLRestServerDB, but only if caching is disable, to avoid version mismatch.
It can be done for some particular tables, like TSQLAuthGroup, TSQLAuthUser.
Note also that the model shall be consistent when accessing the same databases, if you have TSQLRecordReference fields, or use security.
Those RecordReference properties uses the index of a class in the model to identify it in the DB.
And per-table CRUD security, as defined in TSQLAuthGroup rows, also uses the index of a class in the model to identify it.
Offline
Sorry, Ab, I not say clear, I mean external db, I know the order of TSQLRecord should not change, for this reason and organise, I think make more than one model to organise application, since these models all need authentication, then where put TAuthUser and TAuthGroup is a problem, demo code like below, is two model all need put TAuthGroup and TAutoUser or only one model need? thank you!
procedure TForm1.FormCreate(Sender: TObject);
begin
fProps := TOleDBMSSQLConnectionProperties.Create('localhost', 'testdb', '', '');
fModel := CreateModel;
VirtualTableExternalRegisterAll(fModel, fProps);
fDBServer := TSQLRestServerDB.Create(fModel, ChangeFileExt(paramstr(0),'.db3'), true);
fDBServer.CreateMissingTables();
fModel2 := CreateModel2;
VirtualTableExternalRegisterAll(fModel2, fProps);
fDBServer2 := TSQLRestServerDB.Create(fModel2, 'test2.db3', true);
fDBServer2.CreateMissingTables();
fHttpServer := TSQLHttpServer.Create('80', [fDBServer, fDBServer2], '+', useHttpApiRegisteringURI);
fHttpServer.AccessControlAllowOrigin := '*';
end;
Offline
Later I think in some cases this mode is ideal for a site for different corporations, in one site, we can make root1(model1) for corporationA, root2(model2) for corporationB, in Model1 we can use sub-class TAuthGroup1 and TAuthUser1, in Model2 we can use sub-class TAuthGroup2 and TAuthUser2, then in one external DB, we can server two different corporation, great! If share and separate two mode all support, that would be great!
Offline
You can use the same class in several models, without the need of inheriting it.
In fact, in revision 1.18, there are two classes in mORMot.pas to store the model information for each TSQLRecord:
- TSQLRecordProperties which is share by all models, which contain only common RTTI information;
- TSQLModelRecordProperties which has one instance per model, with the corresponding per-model information.
See the documentation of both classes.
You should better use it as external databases, but not SQLite3 instances, unless you share the same TSQLDBSQlite3Properties instance for all models.
Also ensure that caching is disable for those tables, or at least that there is a decent small timeout to allow replication of any modification in other models.
Offline
Thank you for your guidance, continue to read the documentation.
Offline