我正在测试一个在 RethinkDB 数据库的多个表中插入或删除数据的 API。为了在使用 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
在运行此脚本之前,我将运行rethinkdb --port-offset 1
以初始化 RethinkDB 数据库。
运行此脚本后,我想将数据插入table1
或table2
(例如,使用 web UI at localhost:8081
)并查看运行脚本的终端中打印的更改。但是,这似乎不起作用,因为r.table('table1' and 'table2')
可能不是有效的 ReQL 查询。
如何监控两个表中的更改?