Skip to content

Instantly share code, notes, and snippets.

@craigderington
Created March 12, 2019 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigderington/ab6b125840bdab8116b820bf3061209c to your computer and use it in GitHub Desktop.
Save craigderington/ab6b125840bdab8116b820bf3061209c to your computer and use it in GitHub Desktop.
Python3 Socket Server SQLAlchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('mysql://user:pass@localhost/RadioData', convert_unicode=True, pool_pre_ping=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
session = db_session()
def init_db():
# import all modules here that might define models so that
# they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db()
import models
Base.metadata.create_all(bind=engine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment