SQLAlchemy introspection of ORM classes/objects

Posted by Adam Batkin on Stack Overflow See other posts from Stack Overflow or by Adam Batkin
Published on 2010-05-06T22:36:48Z Indexed on 2010/05/06 22:38 UTC
Read the original article Hit count: 254

Filed under:
|
|

I am looking for a way to introspect SQLAlchemy ORM classes/entities to determine the types and other constraints (like maximum lengths) of an entity's properties.

For example, if I have a declarative class:

class User(Base):
    __tablename__ = "USER_TABLE"

    id = sa.Column(sa.types.Integer, primary_key=True)
    fullname = sa.Column(sa.types.String(100))
    username = sa.Column(sa.types.String(20), nullable=False)
    password = sa.Column(sa.types.String(20), nullable=False)
    created_timestamp = sa.Column(sa.types.DateTime, nullable=False)

I would want to be able to find out that the 'fullname' field should be a String with a maximum length of 100, and is nullable. And the 'created_timestamp' field is a DateTime and is not nullable.

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy