2

Say I create a model using SQLAlchemy.

class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, primary_key=True)
    name = Column(String)
    fullname = Column(String)
    password = Column(String)

How do i create a dict of column:sql datatypes?

For example:

_dict = {
    'id': Integer,
    'name': String,
    'fullname': String,
    'password': String
}

Ultimitely, I would like to pass this dict to pandas to_sql function.

1 Answer 1

4

You could just build your dictionary from the columns of the table underlying your mapped class:

_dict = {c.name: c.type for c in User.__table__.c}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.