Answers for "how to get column name in db from an sqlalchemy attribute model"

SQL
0

how to get column name in db from an sqlalchemy attribute model

class User(Base):
    __tablename__ = 'user'
    id = Column('id', String(40), primary_key=True)
    email = Column('email', String(50))
    firstName = Column('first_name', String(25))
    lastName = Column('last_name', String(25))
    addressOne = Column('address_one', String(255))


from sqlalchemy.inspection import inspect
# columns = [column.name for column in inspect(model).c]

# Also if we want to know that User.firstName is first_name then:
columnNameInDb = inspect(User).c.firstName.name
# The following will print: first_name
print(columnNameInDb)
Posted by: Guest on January-21-2021

Code answers related to "how to get column name in db from an sqlalchemy attribute model"

Code answers related to "SQL"

Browse Popular Code Answers by Language