Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 9c30d90

Browse files
committed
add bind_params to query
1 parent d370895 commit 9c30d90

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

influxdb/_dataframe_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def write_points(self,
142142
def query(self,
143143
query,
144144
params=None,
145+
bind_params=None,
145146
epoch=None,
146147
expected_response_code=200,
147148
database=None,
@@ -155,6 +156,10 @@ def query(self,
155156
156157
:param query: the actual query string
157158
:param params: additional parameters for the request, defaults to {}
159+
:param bind_params: bind parameters for the query:
160+
any variable in the query written as `$var_name` will be replaced
161+
with `bind_params['var_name']`. Only works in the `WHERE` clause
162+
and takes precedence over params['params']
158163
:param epoch: response timestamps to be in epoch format either 'h',
159164
'm', 's', 'ms', 'u', or 'ns',defaults to `None` which is
160165
RFC3339 UTC format with nanosecond precision
@@ -172,6 +177,7 @@ def query(self,
172177
:rtype: :class:`~.ResultSet`
173178
"""
174179
query_args = dict(params=params,
180+
bind_params=bind_params,
175181
epoch=epoch,
176182
expected_response_code=expected_response_code,
177183
raise_errors=raise_errors,

influxdb/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def _read_chunked_response(response, raise_errors=True):
345345
def query(self,
346346
query,
347347
params=None,
348+
bind_params=None,
348349
epoch=None,
349350
expected_response_code=200,
350351
database=None,
@@ -361,6 +362,12 @@ def query(self,
361362
defaults to {}
362363
:type params: dict
363364
365+
:param bind_params: bind parameters for the query:
366+
any variable in the query written as `$var_name` will be replaced
367+
with `bind_params['var_name']`. Only works in the `WHERE` clause
368+
and takes precedence over params['params']
369+
:type bind_params: dict
370+
364371
:param epoch: response timestamps to be in epoch format either 'h',
365372
'm', 's', 'ms', 'u', or 'ns',defaults to `None` which is
366373
RFC3339 UTC format with nanosecond precision
@@ -394,6 +401,12 @@ def query(self,
394401
if params is None:
395402
params = {}
396403

404+
if bind_params is not None:
405+
params_dict = json.loads(params.get('params', '{}'))
406+
params_dict.update(bind_params)
407+
params['params'] = json.dumps(params_dict)
408+
409+
397410
params['q'] = query
398411
params['db'] = database or self._database
399412

0 commit comments

Comments
 (0)