我试图将以下查询移植到SQLAlchemy:
SELECT u.username, GROUP_CONCAT(DISTINCT userS.name)
FROM Skills AS filterS
INNER JOIN UserSkills AS ufs ON filterS.id = ufs.skill_id
INNER JOIN Users AS u ON ufs.user_id = u.id
INNER JOIN UserSkills AS us ON u.id = us.user_id
INNER JOIN Skills AS userS ON us.skill_id = userS.id
WHERE filterS.name IN ('C#', 'SQL')
GROUP BY u.id;
Run Code Online (Sandbox Code Playgroud)
我不明白如何在SQLAlchemy中实现AS语句.这是我目前拥有的:
# User class has attribute skills, that points to class UserSkill
# UserSkill class has attribute skill, that points to class Skill
db.session.query(User.id, User.username, func.group_concat(Skill.name).label('skills')).\
join(User.skills).\ …Run Code Online (Sandbox Code Playgroud) 我在单独的文件中定义了一个 Websocket 端点,例如:
from starlette.endpoints import WebSocketEndpoint
from connection_service import ConnectionService
class WSEndpoint(WebSocketEndpoint):
"""Handles Websocket connections"""
async def on_connect(self,
websocket: WebSocket,
connectionService: ConnectionService = Depends(ConnectionService)):
"""Handles new connection"""
self.connectionService = connectionService
...
Run Code Online (Sandbox Code Playgroud)
并在main.py我将端点注册为:
from fastapi import FastAPI
from starlette.routing import WebSocketRoute
from ws_endpoint import WSEndpoint
app = FastAPI(routes=[ WebSocketRoute("/ws", WSEndpoint) ])
Run Code Online (Sandbox Code Playgroud)
但Depends我的终点从未解决。有办法让它发挥作用吗?
另外,FastAPI 中这种机制的目的是什么?我们不能只使用局部/全局变量吗?
python dependency-injection web-frameworks websocket fastapi
我正在使用httpx库,但我认为aiohttp的原理是相同的。如果我在应用程序的整个生命周期中为多个请求创建并重用 AsyncClient,我是否需要在应用程序关闭事件时调用aclose()(或者如果使用 Client)?close或者这些联系会自行消失。
如果我在 Docker 容器中运行应用程序会怎样?这也会是一个因素吗?
我不明白 AsyncClient 或 Client (或 aoihttp 中的 ClientSession)对象下面发生了什么。
感谢帮助。
对于 geojson 类型文件,命名data如下:
{
"type": "FeatureCollection",
"name": "entities",
"features": [{
"type": "Feature",
"properties": {
"Layer": "0",
"SubClasses": "AcDbEntity:AcDbPolyline",
"EntityHandle": "1A0"
},
"geometry": {
"type": "LineString",
"coordinates": [
[3220.136443006845184, 3001.530372177397112],
[3847.34171007254281, 3000.86074447018018],
[3847.34171007254281, 2785.240077064262096],
[3260.34191304818205, 2785.240077064262096],
[3260.34191304818205, 2795.954148466309107]
]
}
},
{
"type": "Feature",
"properties": {
"Layer": "0",
"SubClasses": "AcDbEntity:AcDbPolyline",
"EntityHandle": "1A4"
},
"geometry": {
"type": "LineString",
"coordinates": [
[3611.469650131302842, 2846.845982610575902],
[3695.231030111376185, 2846.845982610575902],
[3695.231030111376185, 2785.240077064262096],
[3611.469650131302842, 2785.240077064262096],
[3611.469650131302842, 2846.845982610575902]
]
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我希望实现以下操作data:
EntityHandle …python ×4
fastapi ×2
aiohttp ×1
geojson ×1
httprequest ×1
httpx ×1
json ×1
sqlalchemy ×1
websocket ×1