8

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!

PJK
  • 2,082
  • 3
  • 17
  • 28

2 Answers2

11

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
aleclarson
  • 18,087
  • 14
  • 64
  • 91
Jens
  • 5,767
  • 5
  • 54
  • 69
10

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.

neumino
  • 4,342
  • 1
  • 18
  • 17