Skip to content

Instantly share code, notes, and snippets.

@ssomnoremac
Last active May 1, 2018 14:44
Show Gist options
  • Save ssomnoremac/22d9c32fafe50f043b4234ffbf1da925 to your computer and use it in GitHub Desktop.
Save ssomnoremac/22d9c32fafe50f043b4234ffbf1da925 to your computer and use it in GitHub Desktop.
database connection for graphene using sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base, DeferredReflection
from sqlalchemy.orm import scoped_session, sessionmaker
connection_string = << your connection string here >>
engine = create_engine(connection_string)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base(cls=DeferredReflection)
Base.query = db_session.query_property()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment