Thank you, Mike!

I’m still a little unclear: how would I use different *MetaData* for 
different sets of tables? For example, currently I use this function:



*def create_base(schema: typing.Optional[str] = None) -> typing.Any:    
return declarative_base(        cls=_Base,*
*        metadata=MetaData(schema=schema, 
naming_convention=_NAMING_CONVENTION),*

*        metaclass=_BaseMeta    )*

where I have a custom *_Base* (to supply e.g. useful *__str__* etc. 
helpers) and a custom *_BaseMeta* which derives from *DeclarativeBase*. The 
*MetaData*’s schema is a parameter to that function so that I can create 
different *Base* classes with their own *MetaData*. Using these different 
*Base* classes I then declare different table mappings, each with their own 
*MetaData*.

Or… would I now statically declare a class 
*CommonBase(metaclass=DeclarativeMeta)* (contains the helpers, etc.) and 
then derive specific classes with their respective *MetaData*, e.g.

*class Base(CommonBase):*
*    metadata = MetaData(schema=schema, 
naming_convention=_NAMING_CONVENTION)*

Or… maybe I’m thinking about this the wrong way?

Jens


On Saturday, July 30, 2022 at 6:47:24 AM UTC+10 Mike Bayer wrote:

>
> yes use the recipe given at 
> https://docs.sqlalchemy.org/en/14/orm/declarative_styles.html#creating-an-explicit-base-non-dynamically-for-use-with-mypy-similar
>  
> .   That is SQLAlchemy 1.4 documentation.  SQLAlchemy 2.0, when released, 
> moves "declarative_base()" to legacy status for this reason and provides a 
> new base class to use.
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/b5d7be5a-8713-491f-bef4-b662f7d7cc53n%40googlegroups.com.

Reply via email to