Created
March 12, 2019 13:43
-
-
Save craigderington/ab6b125840bdab8116b820bf3061209c to your computer and use it in GitHub Desktop.
Python3 Socket Server SQLAlchemy
This file contains 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 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