Aurilius/FireDAC/PostgreSQL - how to dynamically desigate a schemea?

There is a previous post on this: How to designate PostgreSQL schemea?


Basically, we can specify schema name with table name with Aurelius.

My question is - is there a way to dynamically change the schema name? For example, the following entity, I'd like to change the schema name 'dbo' based on the month of the year, like 'dbo-20210312', is that doable?

[Table('Orders', 'dbo')]
TOrder = class(TObject)

Second question: is it possible to create a postgresql schema, using Aurelius? maybe by calling a stored procedure? Something like, before establishing a connection to postgresql server, I'd like to check if the schema exists, if not , create; then connect to the newly created schema. --- is that doable with Aurelius?

Any advice or suggestion is appreciated.

Thank you

I figured out using FireDAC TFDQuery to create schema dynamically based on some name-convention.

But now I need to find out how to "dynamically" change Entity's schema name, for example, the following Entity has a static schema 'dbo' defined - is there away to "intercept" the schema name during run time, and append something like "dbo-20210312"?

[Table('Orders', 'dbo')]
TOrder = class(TObject)

You can do something like this:

Explorer.Manager.EntityTypeFromClass(TOrder).Table.Schema := 'dbo-20210312';
1 Like

This seems the only way that currently works for me. I have many tables, and it would be tedious to change the schema name one by one.


any way to get the list of table classes, from MapperExplorer, so I can enumerate and change their Schema names in a loop?

I think I can take advantage of the function RegisterEntity (redefine it) to internally save the entity's fully qualified name to a list. Then later I can use the list to loop-update the schema names.

But I am not sure if this is an elegant way. So, if there is better way, please advise......

You can get it from explorer:

for EntityClass in Manager.Explorer.Hierarchy.Classes do ...
1 Like

Exactly what I need. Thank you very much!

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.