Script Development / Connector Object DFF.CONN / InfluxDB
The InfluxDB connector operation object is a wrapper of the Python third-party package influxdb (version 5.3.1), mainly providing methods for querying and writing to InfluxDB. This connector is compatible with the following databases:
- Alibaba Cloud Time Series Database InfluxDB Edition
This connector connects based on the HTTP protocol
The parameters of DFF.CONN(...) are as follows:
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
connector_id |
str | Required | Connector ID |
database |
str | None |
Database to use |
.query(...)
Executes an InfluxQL statement. The parameters are as follows:
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
sql |
str | Required | InfluxQL statement, which can contain bind parameter placeholders in the form of $var_name |
bind_params |
dict | None |
Bind parameters |
database |
str | None |
Database to use for this query |
dict_output |
bool | False |
Whether to convert each row of data into the {column_name: value} form |
| Example | |
|---|---|
1 2 3 | |
| Output Example | |
|---|---|
1 | |
| Example 2 (specifying the return result as dictionary format) | |
|---|---|
1 2 3 | |
| Output Example | |
|---|---|
1 | |
A single query returns a dict; when the driver returns multiple result sets for multiple statements, this method returns list[dict].
.query2(...)
The query2(...) method is also used to execute InfluxQL statements, but the parameter placeholder is different, using the question mark ? as the parameter placeholder. The parameters are as follows:
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
sql |
str | Required | InfluxQL statement, which can contain 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 |
Database to use for this query |
dict_output |
bool | False |
Whether to convert each row of data into the {"column name": "value"} form |
| Example | |
|---|---|
1 2 3 | |
Dynamic SQL Statement
query2(...) internally uses DFF.SQL(...) to construct SQL statements and supports constructing complex dynamic SQL statements.
For example, WHERE IN (...) with an uncertain number of values, or INSERT INTO ... VALUES ... for batch writing data, etc.
For details, please refer to Script Development / SQL Construction DFF.SQL
.switch_database(...)
Switch the default database used for subsequent requests of the current operation object.
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
database |
str | Required | Database name |
| Example | |
|---|---|
1 2 | |
If you only need to specify a database for a single query or write, you should prefer using the database parameter of the corresponding method.
.write_point(...)
Added in version 1.1.13
Writes a single data point. The parameters are as follows:
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
measurement |
str | Required | Measurement |
fields |
dict{str: str/int/float/bool} | Required | Field Key name must be str Key value can be str/int/float/bool |
tags |
dict{str: str} | None |
Tag Both key names and key values 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 the database for this write |
| Example | |
|---|---|
1 2 3 | |
.write_points(...)
Added in version 1.1.13
Writes data points in batch. The 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 | Field Key name must be str Key value can be str/int/float/bool |
points[#]['tags'] |
dict{str: str} | None |
Tag Both key names and key values 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 the database for this write |
| Example | |
|---|---|
1 2 3 4 5 6 7 8 | |