Created
March 18, 2015 14:38
-
-
Save joetastic/a758f8a39120749a93af 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 create_engine, Column, Integer, String | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import sessionmaker | |
from tornado.options import options | |
def get_engine(memo=[]): | |
if len(memo) == 0: | |
memo.append( | |
create_engine(options.database_url) | |
) | |
return memo[0] | |
def get_session(memo=[]): | |
if len(memo) == 0: | |
memo.append( | |
sessionmaker(bind=get_engine()) | |
) | |
return memo[0]() | |
Base = declarative_base() | |
class User(Base): | |
__tablename__ = 'user' | |
id = Column(Integer, primary_key=True) | |
name = Column(String) | |
email = Column(String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment