从Nicola's SO answer here和我自己的测试中可以清楚地看出,Eve不支持在资源端点进行条件删除。
我知道我可以对要删除的文档的_ids和_etags使用GET: "where={...}"请求,然后在每个项目终结点发送一系列请求来删除它们,并将If-Match头适当地设置为每个项目的_etag
for each item:
DELETE: http://localhost:5000/items/<item._id>如果可能的话,我想避免发送多个...but请求。
一种解决方案可能是predefined database filters,但这些是静态过滤器,我希望根据一些URL参数动态过滤删除。Pre-event hooks可能就是我正在寻找的解决方案。
Eve是否支持批量删除?如果没有,那么扩展Eve的功能以提供条件和/或批量删除的推荐方式是什么?
发布于 2017-04-12 02:28:38
我添加了一个要删除的事件前钩子,这似乎适用于我到目前为止运行的测试:
def add_delete_filters(resource, request, lookup):
if 'where' in request.args:
conditions = request.args.getlist('where')
for cond_str in conditions:
cond = json.loads(cond_str)
for attrib in cond:
lookup[attrib] = cond[attrib]
app = Eve()
app.on_pre_DELETE += add_delete_filtershttps://stackoverflow.com/questions/43268784
复制相似问题