开发者

SQLAlchemy EXISTS queryset

开发者 https://www.devze.com 2023-04-02 06:10 出处:网络
I use only django framework with his ORM. And there is some code: User.objects.filter(username=\'test\').exists()

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

精彩评论

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