Skip to content

Instantly share code, notes, and snippets.

@mwcampbell
Created July 28, 2011 15:03
Show Gist options
  • Save mwcampbell/1111706 to your computer and use it in GitHub Desktop.
Save mwcampbell/1111706 to your computer and use it in GitHub Desktop.
# Omitting typical SQLAlchemy setup
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
username = Column(String(32))
# ...
class Users(object):
def __getitem(self, username):
session = DBSession()
try:
return session.query(User).filter_by(username=username).one()
except:
raise KeyError, username
def get_root():
return {"users": Users()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment