Last active
November 26, 2017 07:02
-
-
Save bosukh/72674a97a7bcd223e1d739ce474b2b68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sqlalchemy import Column, Integer, String, create_engine | |
| from sqlalchemy.dialects.mysql import DATE | |
| from sqlalchemy.orm import scoped_session, sessionmaker | |
| from sqlalchemy.ext.declarative import declarative_base | |
| class Customer(Base): | |
| __tablename__ = "customer" | |
| id = Column(Integer, primary_key=True, autoincrement=True) | |
| name = Column(String(50), nullable=False) | |
| date_of_birth = Column(DATE, nullable=False) | |
| def init_sqlalchemy(remove=True): | |
| global engine | |
| engine = create_engine(dbname, echo=False) | |
| DBSession.remove() | |
| DBSession.configure(bind=engine, autoflush=False, expire_on_commit=False) | |
| if remove: | |
| # this will remove the exisitng customer table and create a new one. | |
| Base.metadata.drop_all(engine) | |
| Base.metadata.create_all(engine) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment