我想知道是否有一种方法可以直接从 python REPL调用async函数?await
因此以以下代码为例:
import aiohttp
import asyncio
async def somefunc():
async with aiohttp.ClientSession() as session:
host_url = 'https://somehost'
async with session.get(host_url) as resp:
response = await resp.json()
return response
Run Code Online (Sandbox Code Playgroud)
我正在寻找的是一种调试类似功能的简单方法,基本上我想
>>> result = await somefunc()
Run Code Online (Sandbox Code Playgroud)
我知道这可以通过
import asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(somefunc())
Run Code Online (Sandbox Code Playgroud)
但是使用这种方法,我需要更改 somefunc 的主体来记录响应的结果,或者使用额外的异步函数(如下所示)来打印结果
async def result_print():
result = await somefunc()
print(result)
loop = asyncio.get_event_loop()
loop.run_until_complete(result_print())
Run Code Online (Sandbox Code Playgroud)
总结以上内容,我正在寻找一种更方便的方法来在 python REPL 中等待异步函数,也许是一个自定义 REPL 实现,允许
>>> result = await somefunc()
Run Code Online (Sandbox Code Playgroud)
或者可能有一种方法可以在我不知道的 python 默认 repl 中做到这一点?
如何执行嵌套包含?我的表产品与注释有一对多的关系,表注释与users表有多对一的关系.所以评论有user_id和product_id.我的代码是这样的
var models = require('../models');
models.products.findAll({
include: [
{model: models.comments}
]
}).then(function (products) {
next(products);
}).catch(function (err) {
next(err);
});
});
Run Code Online (Sandbox Code Playgroud)
我得到了评论,但我想有类似的东西
models.products.findAll({
include: [
{model: models.comments.include(models.comments.users)}
]
})
Run Code Online (Sandbox Code Playgroud)
没有编写自定义查询,这可能吗?
我有可以有子类别的类别
当我执行findAll时,我想包括所有嵌套的内容,但我不知道深度。
var includeCondition = {
include: [
{
model: models.categories,
as:'subcategory', nested: true
}]
};
models.categories.findAll(includeCondition)
.then(function (categories) {
resolve(categories);
})
.catch(function (err) {
reject(err);
})
});
Run Code Online (Sandbox Code Playgroud)
结果使我只嵌套了一个级别的包含。
[
{
dataValues:{
},
subcategory:{
model:{
dataValues:{
}
// no subcategory here
}
}
}
]
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式使sequalize包含那些嵌套的子类别吗?
我正在使用AWS API Gateway和它的HTTP代理,
我需要通过AWS API Gateway将Authorization标头传递给我的端点
我试过的事情:
像这样设置方法请求,
这不起作用,我的应用程序没有收到授权标题,
我也尝试过使用映射模板
{
"method": "$context.httpMethod",
"body" : $input.json('$'),
"headers": {
#foreach($param in $input.params().header.keySet())
"$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end
#end
},
"queryParams": {
#foreach($param in $input.params().querystring.keySet())
"$param": "$util.escapeJavaScript($input.params().querystring.get($param))" #if($foreach.hasNext),#end
#end
},
"pathParams": {
#foreach($param in $input.params().path.keySet())
"$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end
#end
}
}
Run Code Online (Sandbox Code Playgroud)
这也行不通.
任何人都可以给我一些关于如何实现这一点的暗示吗?
javascript ×2
mysql ×2
sequelize.js ×2
amazon ×1
asynchronous ×1
jointable ×1
orm ×1
python ×1