You are not logged in.
Following this query "How to get a string copy of CreateSQLMultiIndex", @ab implemented two extra really cool callbacks to facilitate PostgreSQL partitioned tables in mormot.orm.sql.pas :
- TRestStorageExternal.OnEngineCreate, for customize-creating the parent partitioned table
- TRestStorageExternal.OnEngineCreateMultiIndex for customize-creating index for the child partitions
However, some problems on using them - in the following code, (FServer.OrmInstance as TRestOrmServer).StaticDataServer[LTable] as TRestStorageExternal would return nil (the nil is set at line 594, mormot.orm.server, where fStaticData = nil, causing the result set to be nil).
Any advice or insights?
VirtualTableExternalRegister(FSQLModel, ATables, FSQLDBConnectionProps);
FServer := TRestServerDB.Create(FSQLModel, SQLITE_MEMORY_DATABASE_NAME, False, '');
if FSQLDBConnectionProps.Dbms = dPostgreSQL then
begin
for var LTable in ATables do
begin
var LStorExt := (FServer.OrmInstance as TRestOrmServer).StaticDataServer[LTable] as TRestStorageExternal; // <=<= This returns LStorExt = nil
LStorExt.OnEngineCreate := AOnEngineCreate;
LStorExt.OnEngineCreateMultiIndex := AOnEngineCreateMultiIndex;
end;
end;
FServer.CreateMissingTables;
Last edited by wxinix (2021-10-05 12:40:47)
Offline
I have moved external table/field/index creation customization callbacks to TSqlDBConnectionProperties.
Now you should be able to customize the process as you expect.
Offline
I have moved external table/field/index creation customization callbacks to TSqlDBConnectionProperties.
Now you should be able to customize the process as you expect.
Thank you ab!
With these callbacks affiliated with TSqlDBConnectionProperties, it is more logical (than with TRestStorageExternal). The entire workflow is much better organized.
Everything works like a CHARM, clean and beautiful.
Thank you again for this wonderful work.
Last edited by wxinix (2021-10-06 16:44:13)
Offline
In the OnTableCreate handler, what is the best way to determine the Table Creation result (True / False)?
TRestStorageExternal has a method ExecuteDirect which would return a boolean, but it is not accessible from TSqlDBConnectionProperties.
function TMormotOrmModel.OnTableCreate(ASender: TSqlDBConnectionProperties; const ATableName: RawUtf8; const
AColumns: TSqlDBColumnCreateDynArray; const ASQL: RawUtf8): Boolean;
begin
ASender.ExecuteNoResult(ASQL, []); // <<--- how to determine if this table-creation Query is successful or not?
end;
Edit:
Is it possible to changed the callback parameter const ATableName: RawUtf8 to const ATable: TOrmClass?
Last edited by wxinix (2021-10-06 21:37:26)
Offline
@ab Is there a way otherwise elegant to obtain the TOrmClass info from inside the callbacks?
Offline
The easiest is to define your callback in the context of the TRestServer instance, so that it can access the TModel and therefore find the TOrmClass from the table name.
Offline
The easiest is to define your callback in the context of the TRestServer instance, so that it can access the TModel and therefore find the TOrmClass from the table name.
That is what I thought, but I just was just asking in case there might be more elegant way from mORMot2 framework side.
Offline