How to get the database and table name from a ReQL query

限于喜欢 提交于 2019-12-10 10:56:18

问题


Suppose I have the following RethinkDB query (as printed in iPython):

In [32]: data_to_archive
Out[32]: <RqlQuery instance: r.db('sensor_db').table('sensor_data').filter(lambda var_2: (r.row['timestamp'] < (r.now() - r.expr(259200.0)))) >

The query is on the database sensor_db and table sensor_data, as is clear from the printed output. Is there any way I can retrieve this information as an attribute of the RqlQuery instance?

(The reason I want to do this is to write succinct code: the query, the database, and the table are currently all passed separated as input arguments to a function, but the latter two are actually contained in the former).


回答1:


Not sure if it exists. Meanwhile, a little ugliness hasn't really hurt anyone except my mom:

In [57]: mom = lambda q, fn: re.search(fn + "\(\'(.*?)\'\)", str(q)).group(1)

In [58]: rql = r.db("foo").table('bar').filter(lambda x: x)

In [59]: mom(rql, 'db')
Out[59]: 'foo'

In [60]: mom(rql, 'table')
Out[60]: 'bar'


来源:https://stackoverflow.com/questions/40025181/how-to-get-the-database-and-table-name-from-a-reql-query

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