python - 如何在sqlalchemy async中获取具有特定属性的所有id列表
问题描述
嘿,我正在尝试学习 sqlalchemy,但我被困在获取状态为 ON 的所有用户 ID 的列表中。该查询在异步 sqlalchemy 中不起作用。
我试过这个,但它不起作用。
async def free_user():
stmt = select(User).where(User.state =='ON')
async with async_session() as session:
result = await session.execute(stmt)
return result.first()
解决方案
您可以使用all()
检索列表中的所有行:
...
async with async_session() as session:
result = await session.execute(stmt)
return result.all()
推荐阅读
- c++ - 代码完成在 C++2a 的 Clion 2019.1 中不起作用
- laravel - 使用没有 jquery 的引导模式提交表单并在日历中显示事件
- sql - ORA-00917: PLSQL 中缺少逗号
- drop-down-menu - Flutter - 如何从 DropdownButton 对齐所选项目?
- java - 如何使用 apigateway 保护基于 Java 的 REST API
- google-cloud-platform - 匿名调用者没有 storage.objects.create 访问权限,但我的 JWT 有范围 https://www.googleapis.com/auth/devstorage.full_control
- mysql - 为房地产连接 4 个 MySql 表
- mysql - Hibernate Criteria Query 使用 MySQL REPLACE 和 CONCAT 函数
- python - 无法将字符串转换为浮点数
- styles - 在选择时将 wfs 属性显示为标签