The C# .NET client that provides an easy and convenient way to interact with InfluxDB 3. This package supports both writing data to InfluxDB and querying data using the FlightSQL client, which allows you to execute SQL queries against InfluxDB IOx.
Add the latest version of the client to your project:
dotnet add package InfluxDB3.Client
To start with the client, import the InfluxDB3.Client
package and create a InfluxDBClient
by constructor initializer:
using System.Threading.Tasks;
using InfluxDB3.Client;
using InfluxDB3.Client.Write;
namespace InfluxDB3.Examples.IOx;
public class IOxExample
{
static async Task Main(string[] args)
{
const string hostUrl = "https://us-east-1-1.aws.cloud2.influxdata.com";
const string authToken = "my-token";
const string database = "my-database";
using var client = new InfluxDBClient(hostUrl, authToken: authToken, database: database);
}
}
to insert data, you can use code like this:
//
// Write by Point
//
var point = PointData.Measurement("temperature")
.AddTag("location", "west")
.AddField("value", 55.15)
.SetTimestamp(DateTime.UtcNow.AddSeconds(-10));
await client.WritePointAsync(point: point);
//
// Write by LineProtocol
//
const string record = "temperature,location=north value=60.0";
await client.WriteRecordAsync(record: record);
to query your data, you can use code like this:
//
// Query by SQL
//
const string sql = "select time,location,value from temperature order by time desc limit 10";
Console.WriteLine("{0,-30}{1,-15}{2,-15}", "time", "location", "value");
await foreach (var row in client.Query(query: sql))
{
Console.WriteLine("{0,-30}{1,-15}{2,-15}", row[0], row[1], row[2]);
}
Console.WriteLine();
//
// Query by InfluxQL
//
const string influxQL =
"select MEAN(value) from temperature group by time(1d) fill(none) order by time desc limit 10";
Console.WriteLine("{0,-30}{1,-15}", "time", "mean");
await foreach (var row in client.Query(query: influxQL, queryType: QueryType.InfluxQL))
{
Console.WriteLine("{0,-30}{1,-15}", row[1], row[2]);
}
If you need help, please use our Community Slack or Community Page.
New features and bugs can be reported on GitHub: https://github.com/InfluxCommunity/influxdb3-csharp
If you would like to contribute code you can do through GitHub by forking the repository and sending a pull request into
the main
branch.
The InfluxDB 3 C# .NET Client is released under the MIT License.