如何为数据库中的所有表生成RethinkDB更改源

Kur*_*eek 1 python rethinkdb reql

我正在测试一个API,它在RethinkDB数据库的多个表中插入或删除数据.为了监视使用API​​时数据库发生的情况,我想在其所有表中打印更改.

这是我正在努力实现的一些"伪代码":

import rethinkdb as r

# Prior to running this script, run "rethinkdb --port-offset 1" at the command line
conn = r.connect('localhost', 28016)
if 'test' in r.db_list().run(conn):
    r.db_drop('test').run(conn)
r.db_create('test').run(conn)

r.table_create('table1').run(conn)
r.table_create('table2').run(conn)

feed = r.table('table1' and 'table2').changes().run(conn)
for document in feed:
    print document
Run Code Online (Sandbox Code Playgroud)

在运行此脚本之前,我将运行rethinkdb --port-offset 1初始化RethinkDB数据库.

一旦这个脚本运行,我想将数据插入其中一个table1table2(例如,使用Web UI localhost:8081),并查看运行脚本的终端中打印的更改.但是,这看起来不起作用,因为r.table('table1' and 'table2')它可能不是有效的ReQL查询.

如何监控两个表中的更改?

Atn*_*nNn 5

您可以使用以下方法在单个查询中跟踪多个更改Feed r.union:

r.union(
  r.table('table1').changes(),
  r.table('table2').changes()
).run(conn)
Run Code Online (Sandbox Code Playgroud)