我有一个从数据库中获取所有数据的路由器。这是我的代码:
@router.get('/articles/', response_model=List[articles_schema.Articles])
async def main_endpoint():
query = articles_model.articles.select().where(articles_model.articles.c.status == 2)
return await db.database.fetch_all(query)
Run Code Online (Sandbox Code Playgroud)
响应是一个包含 JSON 对象的数组,如下所示
[
{
"title": "example1",
"content": "example_content1"
},
{
"title": "example2",
"content": "example_content2"
},
]
Run Code Online (Sandbox Code Playgroud)
但我想做出这样的回应:
{
"items": [
{
"title": "example1",
"content": "example_content1"
},
{
"title": "example2",
"content": "example_content2"
},
]
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?请帮忙。先感谢您