Multiple RethinkDB queries in a single query

I am trying to execute several RQL commands in one request to the server, but I can add without much success. I tried r.union , but it only works with sequences. 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!

+8
ruby rethinkdb rethinkdb-ruby
source share
2 answers

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 delete method does not receive an argument.

+9
source share

You can also use do

 r.do( r.table('test').insert({value1: "Hey"}), r.table('test').insert({value2: "Ho"}) ).run(conn); 
  • Requests ranked from last to first
  • The response will be the last result of the request.
+11
source share

All Articles