The situation:
I have a set of 12 tables (representing data by month) that are sharded across 6 databases. I need to get a sample set of data across any of these databases for any given month.
Why I used Classical Mappping Model rather than Declarative Model:
I only require access to 1 of the 12 types of table as I will only be gathering a sample of data for a single given month each time this code is run. The Classical Mapping Model allows me to dynamically define the table name I want to map to at run time, rather than create mappings for all 12 tables across the 6 databases as I believe would be required with Declarative.
The problem:
I am trying to follow the entity_name example given here mapping my month data class to each of the tables for the given month on the 6 different databases.
But am getting an UnmappedClassError
stating that my base class, which all new classes are derived from, 'is not mapped'.
So on trying to initialise one of my new mapped tables type: <class '__main__.db1month1'>
it is reporting UnmappedClassError: Class 'audit.db.orm.mappedclasses.MonthData' is not mapped
.
Any ideas?
If needed I can paste in my code here but I'm worried it's a little long. I am using the map_class_to_some_table
method defined in the entity_name example for the mappings and haven't altered it.
I meet same situation. My method below:
It work well.But @Katie ‘s method is better
Ended up scrapping all that and following this ShardedSession example instead.
My final class looks something like this: