RethinkDB multiple queries in a single request

笑着哭i 提交于 2020-01-13 08:45:10

问题


I'm trying to execute several RQL commands in a single request to server, without much success I may add. I have tried r.union, but it only works with sequences. What I really want:

[r.db(..).table(..).get(id1).delete(),
 r.db(..).table(..).get(id2).delete(),
 r.db(..).table(..).insert(...)].run_all_at_once

Is there any way to do this?

Thanks!


回答1:


You can do

r.expr( [r.db(...).table(...).get(id1).delete(), 
r.db(...).table(...).get(id1).delete(), 
r.db(...).table(...).insert(...) ] ).run(conn)

Note that the method delete doesn't get an argument.




回答2:


You can also use do

r.do(
  r.table('test').insert({value1: "Hey"}),
  r.table('test').insert({value2: "Ho"})
).run(conn);
  • The queries are evaluated from last to first
  • The response will be the last query's result


来源:https://stackoverflow.com/questions/20294097/rethinkdb-multiple-queries-in-a-single-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!