There are lots of ways of doing this. One option is to provide a
dictionary when creating your declarative_base:
classes = {}
Base = declarative_base(class_registry=classes)
Now you can look up classes by name in that classes dictionary:
def get_table_by_name(name):
return classes[name]
Another option could be to iterate over Base.__subclasses__:
def get_table_by_name(name):
for cls in Base.__subclasses__():
if cls.__name__ == name:
return cls
Hope that helps,
Simon
On Tue, Mar 16, 2021 at 7:14 PM FURKAN bilgin <[email protected]> wrote:
>
> table_name = "table_name"
>
> #get table as table
>
> new = table(**tablo)
> db.session.add(table)
> db.session.commit()
>
> --
> 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/c3c7c369-7d7f-41b0-b6f3-273b6c76314dn%40googlegroups.com.
--
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/CAFHwexfPY_VqEeD0Rurc_HDyw%2BnRFsOSGq_Oeo66ZgjBSnEkpg%40mail.gmail.com.