开发者

SQLAlchemy EXISTS queryset

I use only django framework with his ORM.

And there is some code:

User.objects.filter(username='test').exists()

that return True or False.

this orm query generate SQL:

SELECT (1) AS "a" FROM开发者_C百科 "auth_user" WHERE "auth_user"."username" = E'test'  LIMIT 1

How I can perform equal query in SQLAlchemy?

I try understand this page http://www.sqlalchemy.org/docs/05/ormtutorial.html#using-exists but can't understand how this works.

Help please.

Thanks!


(ret,), = Session.query(exists().where(User.username=='test'))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜