Skip to content

Instantly share code, notes, and snippets.

@bosukh
Last active November 26, 2017 07:02
Show Gist options
  • Select an option

  • Save bosukh/72674a97a7bcd223e1d739ce474b2b68 to your computer and use it in GitHub Desktop.

Select an option

Save bosukh/72674a97a7bcd223e1d739ce474b2b68 to your computer and use it in GitHub Desktop.
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