How to get one record with SQLAlchemy?
This should help with getting a single result of falesie
:
try: user = session.query(falesie).filter(name=name).one() # filter on nameexcept MultipleResultsFound, e: print e # Deal with itexcept NoResultFound, e: print e # Deal with that as well
Where session
is obtained as following:
from sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker# an Engine, which the Session will use for connection resourcesengine = create_engine('sqlite:///climb.db')# create a configured "Session" classSession = sessionmaker(bind=engine)# create a Sessionsession = Session()
See SQLAlchemy
documentation for more details.
If you read the tutorial, you'll see that you can filter your query. Something like this should be what you want:
falesie.query().filter_by(id=name).first()
Question is very old but one more technique can help to others having problem.
def load_user(id): falesie.query.get(int(id))