Class InfluxDBClient
Inheritance
Namespace: InfluxDB3.Client
Assembly: InfluxDB3.Client.dll
Syntax
public class InfluxDBClient : object, IInfluxDBClient
Constructors
InfluxDBClient()
Initializes a new instance of the client using connection string.
Supported parameters are:
- INFLUX_HOST - InfluxDB host URL (required)
- INFLUX_TOKEN - authentication token (required)
- INFLUX_AUTH_SCHEME - token authentication scheme (default is
null
for Cloud access) - INFLUX_ORG - organization name
- INFLUX_DATABASE - database (bucket) name
- INFLUX_PRECISION - timestamp precision when writing data (
ns
(default),us
,ms
,s
) - INFLUX_GZIP_THRESHOLD - threshold for gzipping data when writing (default is
1000
)
Declaration
public InfluxDBClient()
Examples
using var client = new InfluxDBClient();
InfluxDBClient(ClientConfig)
Initializes a new instance of the client with provided configuration.
Declaration
public InfluxDBClient(ClientConfig config)
Parameters
Type | Name | Description |
---|---|---|
ClientConfig | config | The configuration of the client. |
Examples
using var client = new InfluxDBClient( new ClientConfig { Host = "https://us-east-1-1.aws.cloud2.influxdata.com", Token = "my-token", Organization = "my-org", Database = "my-database" } );
InfluxDBClient(String)
Initializes a new instance of the client using connection string.
Supported parameters are:
- token - authentication token (required)
- authScheme - token authentication scheme (default
null
for Cloud access) - org - organization name
- database - database (bucket) name
- precision - timestamp precision when writing data (
ns
(default),us
,ms
,s
) - gzipThreshold - threshold for gzip data when writing (default is
1000
)
Declaration
public InfluxDBClient(string connectionString)
Parameters
Type | Name | Description |
---|---|---|
System.String | connectionString | Connection string in URL format. |
Examples
using var client = new InfluxDBClient(host: "https://us-east-1-1.aws.cloud2.influxdata.com?token=my-token&database=my-db");
InfluxDBClient(String, String, Nullable<String>, Nullable<String>, Nullable<String>)
Initializes a new instance of the client with provided configuration options.
Declaration
public InfluxDBClient(string host, string token, string? organization = null, string? database = null, string? authScheme = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | host | The URL of the InfluxDB server. |
System.String | token | The authentication token for accessing the InfluxDB server. |
System.Nullable<System.String> | organization | The organization name to be used for operations. |
System.Nullable<System.String> | database | The database to be used for InfluxDB operations. |
System.Nullable<System.String> | authScheme | Token authentications scheme. |
Examples
using var client = new InfluxDBClient(host: "https://us-east-1-1.aws.cloud2.influxdata.com", token: "my-token", organization: "my-org", database: "my-database");
Methods
Dispose()
Declaration
public void Dispose()
Query(String, Nullable<QueryType>, Nullable<String>, Nullable<Dictionary<String, Object>>, Nullable<Dictionary<String, String>>)
Query data from InfluxDB IOx using FlightSQL.
Declaration
public async IAsyncEnumerable<object? []> Query(string query, QueryType? queryType = null, string? database = null, Dictionary<string, object>? namedParameters = null, Dictionary<string, string>? headers = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | The SQL query string to execute. |
System.Nullable<QueryType> | queryType | The type of query sent to InfluxDB. Default to 'SQL'. |
System.Nullable<System.String> | database | The database to be used for InfluxDB operations. |
System.Nullable<Dictionary<System.String, System.Object>> | namedParameters | Name:Value pairs to use as named parameters for this query. Parameters referenced using '$placeholder' syntax in the query will be substituted with the values provided. The supported types are: string, bool, int, float. |
System.Nullable<Dictionary<System.String, System.String>> | headers | The headers to be added to query request. The headers specified here are preferred over the headers specified in the client configuration. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<System.Nullable<System.Object>[]> | Batches of rows |
Examples
The following example shows how to use SQL query with named parameters:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
var results = client.Query(
query: "SELECT a, b, c FROM my_table WHERE id = $id AND name = $name",
namedParameters: new Dictionary<string, object> { { "id", 1 }, { "name", "test" } }
);
The following example shows how to use custom request headers:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
var results = client.Query(
query: "SELECT a, b, c FROM my_table",
headers: new Dictionary<string, string> { { "X-Tracing-Id", "123" } }
);
QueryBatches(String, Nullable<QueryType>, Nullable<String>, Nullable<Dictionary<String, Object>>, Nullable<Dictionary<String, String>>)
Query data from InfluxDB IOx using FlightSQL.
Declaration
public IAsyncEnumerable<RecordBatch> QueryBatches(string query, QueryType? queryType = null, string? database = null, Dictionary<string, object>? namedParameters = null, Dictionary<string, string>? headers = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | The SQL query string to execute. |
System.Nullable<QueryType> | queryType | The type of query sent to InfluxDB. Default to 'SQL'. |
System.Nullable<System.String> | database | The database to be used for InfluxDB operations. |
System.Nullable<Dictionary<System.String, System.Object>> | namedParameters | Name:Value pairs to use as named parameters for this query. Parameters referenced using '$placeholder' syntax in the query will be substituted with the values provided. The supported types are: string, bool, int, float. |
System.Nullable<Dictionary<System.String, System.String>> | headers | The headers to be added to query request. The headers specified here are preferred over the headers specified in the client configuration. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<RecordBatch> | Batches of rows |
Examples
The following example shows how to use SQL query with named parameters:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
var results = client.QueryBatches(
query: "SELECT a, b, c FROM my_table WHERE id = $id AND name = $name",
namedParameters: new Dictionary<string, object> { { "id", 1 }, { "name", "test" } }
);
The following example shows how to use custom request headers:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
var results = client.QueryBatches(
query: "SELECT a, b, c FROM my_table",
headers: new Dictionary<string, string> { { "X-Tracing-Id", "123" } }
);
QueryPoints(String, Nullable<QueryType>, Nullable<String>, Nullable<Dictionary<String, Object>>, Nullable<Dictionary<String, String>>)
Query data from InfluxDB IOx into PointData structure using FlightSQL.
Declaration
public async IAsyncEnumerable<PointDataValues> QueryPoints(string query, QueryType? queryType = null, string? database = null, Dictionary<string, object>? namedParameters = null, Dictionary<string, string>? headers = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | The SQL query string to execute. |
System.Nullable<QueryType> | queryType | The type of query sent to InfluxDB. Default to 'SQL'. |
System.Nullable<System.String> | database | The database to be used for InfluxDB operations. |
System.Nullable<Dictionary<System.String, System.Object>> | namedParameters | Name:Value pairs to use as named parameters for this query. Parameters referenced using '$placeholder' syntax in the query will be substituted with the values provided. The supported types are: string, bool, int, float. |
System.Nullable<Dictionary<System.String, System.String>> | headers | The headers to be added to query request. The headers specified here are preferred over the headers specified in the client configuration. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<PointDataValues> | Batches of rows |
Examples
The following example shows how to use SQL query with named parameters:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
var results = client.QueryPoints(
query: "SELECT a, b, c FROM my_table WHERE id = $id AND name = $name",
namedParameters: new Dictionary<string, object> { { "id", 1 }, { "name", "test" } }
);
The following example shows how to use custom request headers:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
var results = client.QueryPoints(
query: "SELECT a, b, c FROM my_table",
headers: new Dictionary<string, string> { { "X-Tracing-Id", "123" } }
);
WritePointAsync(PointData, Nullable<String>, Nullable<WritePrecision>, Nullable<Dictionary<String, String>>, CancellationToken)
Write data to InfluxDB.
Declaration
public Task WritePointAsync(PointData point, string? database = null, WritePrecision? precision = null, Dictionary<string, string>? headers = null, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
PointData | point | Specifies the Data point to write into InfluxDB. The |
System.Nullable<System.String> | database | The database to be used for InfluxDB operations. |
System.Nullable<WritePrecision> | precision | The to use for the timestamp in the write API call. |
System.Nullable<Dictionary<System.String, System.String>> | headers | The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration. |
CancellationToken | cancellationToken | specifies the token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task |
Examples
The following example shows how to write a single point with custom headers:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
await client.WritePointAsync(
point: PointData.Measurement("h2o").SetTag("location", "europe").SetField("level", 2),
headers: new Dictionary<string, string> { { "X-Tracing-Id", "123" } }
);
WritePointsAsync(IEnumerable<PointData>, Nullable<String>, Nullable<WritePrecision>, Nullable<Dictionary<String, String>>, CancellationToken)
Write data to InfluxDB.
Declaration
public Task WritePointsAsync(IEnumerable<PointData> points, string? database = null, WritePrecision? precision = null, Dictionary<string, string>? headers = null, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<PointData> | points | Specifies the Data points to write into InfluxDB. The |
System.Nullable<System.String> | database | The database to be used for InfluxDB operations. |
System.Nullable<WritePrecision> | precision | The to use for the timestamp in the write API call. |
System.Nullable<Dictionary<System.String, System.String>> | headers | The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration. |
CancellationToken | cancellationToken | specifies the token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task |
Examples
The following example shows how to write multiple points with custom headers:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
await client.WritePointsAsync(
points: new[]{
PointData.Measurement("h2o").SetTag("location", "europe").SetField("level", 2),
PointData.Measurement("h2o").SetTag("location", "us-west").SetField("level", 4),
},
headers: new Dictionary<string, string> { { "X-Tracing-Id", "123" } }
);
WriteRecordAsync(String, Nullable<String>, Nullable<WritePrecision>, Nullable<Dictionary<String, String>>, CancellationToken)
Write data to InfluxDB.
Declaration
public Task WriteRecordAsync(string record, string? database = null, WritePrecision? precision = null, Dictionary<string, string>? headers = null, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | record | Specifies the record in InfluxDB Line Protocol. The |
System.Nullable<System.String> | database | The database to be used for InfluxDB operations. |
System.Nullable<WritePrecision> | precision | The to use for the timestamp in the write API call. |
System.Nullable<Dictionary<System.String, System.String>> | headers | The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration. |
CancellationToken | cancellationToken | specifies the token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task |
Examples
The following example shows how to write a single record with custom headers:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
await client.WriteRecordAsync(
record: "stat,unit=temperature value=24.5",
headers: new Dictionary<string, string> { { "X-Tracing-Id", "123" } }
);
WriteRecordsAsync(IEnumerable<String>, Nullable<String>, Nullable<WritePrecision>, Nullable<Dictionary<String, String>>, CancellationToken)
Write data to InfluxDB.
Declaration
public Task WriteRecordsAsync(IEnumerable<string> records, string? database = null, WritePrecision? precision = null, Dictionary<string, string>? headers = null, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.String> | records | Specifies the records in InfluxDB Line Protocol. The |
System.Nullable<System.String> | database | The database to be used for InfluxDB operations. |
System.Nullable<WritePrecision> | precision | The to use for the timestamp in the write API call. |
System.Nullable<Dictionary<System.String, System.String>> | headers | The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration. |
CancellationToken | cancellationToken | specifies the token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task |
Examples
The following example shows how to write multiple records with custom headers:
using var client = new InfluxDBClient(host: "http://localhost:8086", token: "my-token", organization: "my-org", database: "my-database");
await client.WriteRecordsAsync(
records: new[] { "stat,unit=temperature value=24.5", "stat,unit=temperature value=25.5" },
headers: new Dictionary<string, string> { { "X-Tracing-Id", "123" } }
);