Reverted recent list_code_example additions
parent
560505d423
commit
0ecbe89eef
|
@ -11,80 +11,6 @@ menu:
|
|||
identifier: influxdb3-csharp
|
||||
influxdb/cloud-dedicated/tags: [C#, gRPC, SQL, Flight SQL, client libraries]
|
||||
weight: 201
|
||||
list_code_example: >
|
||||
```csharp
|
||||
|
||||
// This example demonstrates how to use the InfluxDB v3 C# .NET client library
|
||||
|
||||
// to write sensor data to an InfluxDB database and query data from the last 90 days.
|
||||
|
||||
using System;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using InfluxDB3.Client;
|
||||
|
||||
using InfluxDB3.Client.Api.Domain;
|
||||
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
// Initialize the InfluxDB client
|
||||
var client = new InfluxDBClient("https://your-influxdb-url", "your-auth-token", "your-organization-id", "your-database-name");
|
||||
|
||||
try
|
||||
{
|
||||
// Write sensor data to the database
|
||||
await WriteSensorData(client);
|
||||
|
||||
// Query data from the last 90 days
|
||||
await QuerySensorData(client);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Dispose the client to release resources
|
||||
client.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task WriteSensorData(InfluxDBClient client)
|
||||
{
|
||||
// Create a point with tags, fields, and a timestamp
|
||||
var point = new Point
|
||||
{
|
||||
Measurement = "home",
|
||||
Tags = { { "room", "living_room" } },
|
||||
Fields = { { "temperature", 23.5 } },
|
||||
Timestamp = DateTime.UtcNow
|
||||
};
|
||||
|
||||
// Write the point to the database
|
||||
await client.WritePointAsync(point);
|
||||
Console.WriteLine("Data successfully written to InfluxDB.");
|
||||
}
|
||||
|
||||
private static async Task QuerySensorData(InfluxDBClient client)
|
||||
{
|
||||
// Define the Flux query
|
||||
var query = @"
|
||||
from(bucket: ""your-database-name"")
|
||||
|> range(start: -90d)
|
||||
|> filter(fn: (r) => r._measurement == ""home"")";
|
||||
|
||||
// Execute the query
|
||||
var result = await client.QueryAsync(query);
|
||||
|
||||
// Print the results
|
||||
Console.WriteLine("Queried data:");
|
||||
foreach (var record in result)
|
||||
{
|
||||
Console.WriteLine($"{record.Timestamp}: {record.Values["_value"]}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
The InfluxDB v3 [`influxdb3-csharp` C# .NET client library](https://github.com/InfluxCommunity/influxdb3-csharp) integrates with C# .NET scripts and applications
|
||||
|
|
|
@ -12,83 +12,6 @@ weight: 201
|
|||
aliases:
|
||||
- /influxdb/cloud-dedicated/reference/api/client-libraries/go/
|
||||
- /influxdb/cloud-dedicated/tools/client-libraries/go/
|
||||
list_code_example: >
|
||||
```go
|
||||
|
||||
// This example demonstrates how to use the InfluxDB Go client library
|
||||
|
||||
// to write sensor data to an InfluxDB bucket and query historical data using Flux.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
influxdb3 "github.com/influxdata/influxdb3-go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize the InfluxDB client
|
||||
client, err := influxdb3.NewClient(&influxdb3.Options{
|
||||
Host: "https://your-influxdb-url",
|
||||
Token: "your-auth-token",
|
||||
Org: "your-organization-id",
|
||||
Database: "your-database-name",
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating InfluxDB client: %v", err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
// Write sensor data to the database
|
||||
err = writeSensorData(client)
|
||||
if err != nil {
|
||||
log.Fatalf("Error writing sensor data: %v", err)
|
||||
}
|
||||
|
||||
// Query data from the last 90 days
|
||||
err = querySensorData(client)
|
||||
if err != nil {
|
||||
log.Fatalf("Error querying sensor data: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func writeSensorData(client *influxdb3.Client) error {
|
||||
// Create a point with tags and fields
|
||||
point := influxdb3.NewPointWithMeasurement("home").
|
||||
AddTag("room", "living_room").
|
||||
AddField("temperature", 23.5).
|
||||
SetTimestamp(time.Now())
|
||||
|
||||
// Write the point to the database
|
||||
if err := client.WritePoint(context.Background(), point); err != nil {
|
||||
return fmt.Errorf("failed to write point: %w", err)
|
||||
}
|
||||
fmt.Println("Data successfully written to InfluxDB.")
|
||||
return nil
|
||||
}
|
||||
|
||||
func querySensorData(client *influxdb3.Client) error {
|
||||
// Define the query to retrieve data from the last 90 days
|
||||
query := `from(bucket: "your-database-name")
|
||||
|> range(start: -90d)
|
||||
|> filter(fn: (r) => r._measurement == "home")`
|
||||
|
||||
// Execute the query
|
||||
result, err := client.QueryRaw(context.Background(), query)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute query: %w", err)
|
||||
}
|
||||
|
||||
// Print the results
|
||||
fmt.Println("Queried data:")
|
||||
fmt.Println(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
The InfluxDB v3 [`influxdb3-go` Go client library](https://github.com/InfluxCommunity/influxdb3-go) integrates with Go scripts and applications
|
||||
|
|
|
@ -10,80 +10,6 @@ menu:
|
|||
identifier: influxdb3-java
|
||||
influxdb/cloud-dedicated/tags: [Flight client, Java, gRPC, SQL, Flight SQL, client libraries]
|
||||
weight: 201
|
||||
list_code_example: >
|
||||
```java
|
||||
|
||||
// The following example demonstrates how to write sensor data into InfluxDB
|
||||
|
||||
// and retrieve data from the last 90 days for analysis.
|
||||
|
||||
|
||||
import com.influxdb.client.InfluxDBClient;
|
||||
|
||||
import com.influxdb.client.InfluxDBClientFactory;
|
||||
|
||||
import com.influxdb.client.QueryApi;
|
||||
|
||||
import com.influxdb.client.write.Point;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class InfluxDBExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Initialize the InfluxDB client
|
||||
String url = "https://your-influxdb-url";
|
||||
String token = "your-auth-token";
|
||||
String org = "your-organization-id";
|
||||
String bucket = "your-database-name";
|
||||
|
||||
try (InfluxDBClient client = InfluxDBClientFactory.create(url, token.toCharArray(), org, bucket)) {
|
||||
|
||||
// Write sensor data
|
||||
writeSensorData(client);
|
||||
|
||||
// Query sensor data
|
||||
querySensorData(client);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeSensorData(InfluxDBClient client) {
|
||||
// Create a point
|
||||
Point point = Point.measurement("home")
|
||||
.addTag("room", "living_room")
|
||||
.addField("temperature", 23.5)
|
||||
.time(Instant.now(), WritePrecision.NS);
|
||||
|
||||
// Write the point
|
||||
client.getWriteApiBlocking().writePoint(point);
|
||||
System.out.println("Data successfully written to InfluxDB.");
|
||||
}
|
||||
|
||||
private static void querySensorData(InfluxDBClient client) {
|
||||
// Query data for the last 90 days
|
||||
String query = "from(bucket: \"your-database-name\") "
|
||||
+ "|> range(start: -90d) "
|
||||
+ "|> filter(fn: (r) => r._measurement == \"home\")";
|
||||
|
||||
QueryApi queryApi = client.getQueryApi();
|
||||
|
||||
// Execute the query and retrieve results
|
||||
List<FluxTable> tables = queryApi.query(query);
|
||||
|
||||
// Print the results
|
||||
if (tables != null) {
|
||||
tables.forEach(table -> {
|
||||
table.getRecords().forEach(record -> {
|
||||
System.out.println(record.getTime() + ": " + record.getValueByKey("_value"));
|
||||
});
|
||||
});
|
||||
} else {
|
||||
System.out.println("No data found for the specified query.");
|
||||
}
|
||||
}
|
||||
---
|
||||
|
||||
The InfluxDB v3 [`influxdb3-java` Java client library](https://github.com/InfluxCommunity/influxdb3-java) integrates
|
||||
|
|
|
@ -14,86 +14,8 @@ weight: 201
|
|||
aliases:
|
||||
- /influxdb/cloud-dedicated/reference/api/client-libraries/go/
|
||||
- /influxdb/cloud-dedicated/tools/client-libraries/go/
|
||||
list_code_example: >
|
||||
```javascript
|
||||
Example: Writing and querying data
|
||||
|
||||
// The following example demonstrates how to write sensor data into InfluxDB using the
|
||||
|
||||
// and retrieve data from the last 90 days for analysis.
|
||||
|
||||
|
||||
// Import the InfluxDB client library
|
||||
|
||||
import { InfluxDBClient, Point } from '@influxdata/influxdb3-client';
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
import csv from 'csv-parser';
|
||||
|
||||
|
||||
// Initialize the InfluxDB client
|
||||
|
||||
const client = new InfluxDBClient({
|
||||
host: 'https://your-influxdb-url',
|
||||
token: 'your-auth-token',
|
||||
org: 'your-organization-id',
|
||||
database: 'your-database-name',
|
||||
});
|
||||
|
||||
|
||||
// Function to write sensor data in batches from a CSV file
|
||||
|
||||
const writeSensorData = async (filePath) => {
|
||||
const points = [];
|
||||
fs.createReadStream(filePath)
|
||||
.pipe(csv())
|
||||
.on('data', (row) => {
|
||||
const point = new Point('home')
|
||||
.timestamp(new Date(row['time']))
|
||||
.tag('room', row['room']);
|
||||
points.push(point);
|
||||
})
|
||||
.on('end', async () => {
|
||||
try {
|
||||
await client.write(points);
|
||||
console.log('Data successfully written to InfluxDB.');
|
||||
} catch (error) {
|
||||
console.error('Error writing data to InfluxDB:', error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Function to query data for the last 90 days
|
||||
|
||||
const querySensorData = async () => {
|
||||
const query = `
|
||||
SELECT *
|
||||
FROM home
|
||||
WHERE time >= now() - INTERVAL '90 days'
|
||||
ORDER BY time
|
||||
`;
|
||||
try {
|
||||
const result = await client.query(query);
|
||||
console.log('Queried data:', result);
|
||||
} catch (error) {
|
||||
console.error('Error querying data from InfluxDB:', error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Example usage
|
||||
|
||||
const filePath = './data/home-sensor-data.csv';
|
||||
|
||||
writeSensorData(filePath);
|
||||
|
||||
querySensorData();
|
||||
|
||||
```
|
||||
---
|
||||
|
||||
|
||||
The InfluxDB v3 [`influxdb3-js` JavaScript client library](https://github.com/InfluxCommunity/influxdb3-js) integrates with JavaScript scripts and applications
|
||||
to write and query data stored in an {{% product-name %}} database.
|
||||
|
||||
|
|
Loading…
Reference in New Issue