How to discover table properties from SQLAlchemy mapped object

Posted by ssaboum on Stack Overflow See other posts from Stack Overflow or by ssaboum
Published on 2010-03-14T10:11:10Z Indexed on 2010/03/14 10:15 UTC
Read the original article Hit count: 202

Hi,

My point is 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 :

engine = create_engine('sqlite:///' + databasePath, echo=True)

# setting up root class for declarative declaration
Base = declarative_base(bind=engine)

class Ship(Base):
    __tablename__ = 'ships'

    id = Column(Integer, primary_key=True)
    name = Column(String(255))

    def __init__(self, name):
            self.name = name

    def __repr__(self):
            return "<Ship('%s')>" % (self.name)

So now my goal is from the "Ship" class to get the table columns and their properties from another piece of code. I guess i can deal with it using instrumentation but is there any way provided by the SQLAlchemy API ?

Thank you.

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy