How to discover table properties from SQLAlchemy mapped object

前端 未结 2 1612
南旧
南旧 2020-11-30 03:45

I have a class mapped with a table, in my case in a declarative way, and I want to \"discover\" table properties, columns, names, relations, from this class:



        
2条回答
  •  误落风尘
    2020-11-30 04:49

    If declarative base is not used, the answer fails. The following should work no matter how it's initialized

    For Class Object:

    TableClass.sa_class_manager.mapper.mapped_table.name
    

    For Instance Object:

    tableObj.sa_instance_state.mapper.mapped_table.name
    

提交回复
热议问题