如何从 ReQL 查询中获取数据库和表名 [英] How to get the database and table name from a ReQL query
问题描述
假设我有以下 RethinkDB 查询(在 iPython 中打印):
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)))) >
查询在数据库 sensor_db
和表 sensor_data
上,从打印的输出中可以清楚地看出.有什么方法可以将这些信息作为 RqlQuery
实例的属性来检索?
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).
推荐答案
不确定是否存在.与此同时,除了我妈妈,一点点丑陋并没有真正伤害到任何人:
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'
这篇关于如何从 ReQL 查询中获取数据库和表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!