Script Development / InfluxDB
The InfluxDB connector operation object is a wrapper for the Python third-party package influxdb (version 5.2.3), primarily providing methods for querying InfluxDB. This connector is compatible with the following databases:
- Alibaba Cloud Time Series Database InfluxDB Edition
This connector connects via HTTP protocol
DFF.CONN(...) parameters are as follows:
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
connector_id |
str | Required | Connector ID |
database |
str | None |
Specify database |
.query(...)
Execute an InfluxQL statement. Parameters are as follows:
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
sql |
str | Required | InfluxQL statement, can include bind parameter placeholders in the form $var_name |
bind_params |
dict | None |
Bind parameters |
database |
str | None |
Specify database for this query |
dict_output |
dict | False |
Automatically convert returned data to the form |
| Example | |
|---|---|
1 2 3 | |
| Output Example | |
|---|---|
1 | |
| Example 2 (specify return result as dictionary format) | |
|---|---|
1 2 3 | |
| Output Example | |
|---|---|
1 | |
.query2(...)
The query2(...) method is also used to execute InfluxQL statements, but the parameter placeholders are different, using the question mark ? as the parameter placeholder. Parameters are as follows:
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
sql |
str | Required | InfluxQL statement, can include parameter placeholders.? indicates a parameter that needs escaping;?? indicates a parameter that does not need escaping |
sql_params |
list | None |
InfluxQL parameters |
database |
str | None |
Specify database for this query |
dict_output |
dict | False |
Automatically convert returned data to the form {"column name": "value"} |
| Example | |
|---|---|
1 2 3 | |
Dynamic SQL Statements
query2(...) internally uses DFF.SQL(...) to construct SQL statements and supports building complex dynamic SQL statements.
For example, WHERE IN (...) with an unknown number of values, or INSERT INTO ... VALUES ... for batch data writing, etc.
For details, please refer to Script Development / SQL Construction DFF.SQL
.write_point(...)
Added in version 1.1.13
Write a single data point. Parameters are as follows:
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
measurement |
str | Required | Measurement |
fields |
dict{str: str/int/float/bool} | Required | Fields Key name must be str Key value can be str/int/float/bool |
tags |
dict{str: str} | None |
Tags Key name and key value must be str |
timestamp |
str/int | None |
Time ISO format, e.g.: 2020-01-01T01:02:03ZUNIX timestamp e.g.: 1577840523 |
database |
str | None |
Specify database for this write |
| Example | |
|---|---|
1 2 3 | |
.write_points(...)
Added in version 1.1.13
Batch write data points. Parameters are as follows:
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
points |
list | Required | Array of data points |
points[#]['measurement'] |
str | Required | Measurement |
points[#]['fields'] |
dict{str: str/int/float/bool} | Required | Fields Key name must be str Key value can be str/int/float/bool |
points[#]['tags'] |
dict{str: str} | None |
Tags Key name and key value must be str |
points[#]['time'] |
str/int | None |
Time ISO format, e.g.: 2020-01-01T01:02:03ZUNIX timestamp e.g.: 1577840523 |
database |
str | None |
Specify database for this write |
| Example | |
|---|---|
1 2 3 4 5 6 7 8 | |