From 317a3068f67b03182ecf87708237a65443b81729 Mon Sep 17 00:00:00 2001
From: karel rehor
- Add the following function to the end of your{' '}
+ The following snippet introduces query parameters for the model query above.
+ The fixed values "bees" and "ants" are replaced with "species1" and "species2".
+ Add this to the end of your{' '}
main
function:
You'll need to have{' '}
diff --git a/src/homepageExperience/components/steps/go/WriteData.tsx b/src/homepageExperience/components/steps/go/WriteData.tsx
index e0b03a6db9..b40d379610 100644
--- a/src/homepageExperience/components/steps/go/WriteData.tsx
+++ b/src/homepageExperience/components/steps/go/WriteData.tsx
@@ -48,7 +48,8 @@ export const WriteDataComponent = (props: OwnProps) => {
onSelectBucket(bucket.name)
}, [bucket, onSelectBucket])
- const codeSnippet = `org := "${org.name}"
+ const codeSnippet = `// FOO
+org := "${org.name}"
bucket := "${bucket.name}"
writeAPI := client.WriteAPIBlocking(org, bucket)
for value := 0; value < 5; value++ {
diff --git a/src/homepageExperience/components/steps/go/WriteDataSql.tsx b/src/homepageExperience/components/steps/go/WriteDataSql.tsx
index d5a3492754..c88348ba0c 100644
--- a/src/homepageExperience/components/steps/go/WriteDataSql.tsx
+++ b/src/homepageExperience/components/steps/go/WriteDataSql.tsx
@@ -61,13 +61,14 @@ export const WriteDataSqlComponent = (props: OwnProps) => {
}, [bucket, onSelectBucket])
const initializeCodeSnippet = `package main
-
+
import (
"context"
"fmt"
"time"
+ "os"
- "github.com/InfluxCommunity/influxdb3-go/influxdb3"
+ "github.com/InfluxCommunity/influxdb3-go/v2/influxdb3"
)
func main() {
@@ -95,55 +96,61 @@ func main() {
database := "${bucket.name}"
}`
- const writeCodeSnippet = `data := map[string]map[string]interface{}{
- "point1": {
- "location": "Klamath",
- "species": "bees",
- "count": 23,
- },
- "point2": {
- "location": "Portland",
- "species": "ants",
- "count": 30,
- },
- "point3": {
- "location": "Klamath",
- "species": "bees",
- "count": 28,
- },
- "point4": {
- "location": "Portland",
- "species": "ants",
- "count": 32,
- },
- "point5": {
- "location": "Klamath",
- "species": "bees",
- "count": 29,
- },
- "point6": {
- "location": "Portland",
- "species": "ants",
- "count": 40,
- },
-}
+ const writeCodeSnippet = ` data := map[string]map[string]interface{}{
+ "point1": {
+ "location": "Klamath",
+ "species": "bees",
+ "count": 23,
+ },
+ "point2": {
+ "location": "Portland",
+ "species": "ants",
+ "count": 30,
+ },
+ "point3": {
+ "location": "Klamath",
+ "species": "bees",
+ "count": 28,
+ },
+ "point4": {
+ "location": "Portland",
+ "species": "ants",
+ "count": 32,
+ },
+ "point5": {
+ "location": "Klamath",
+ "species": "bees",
+ "count": 29,
+ },
+ "point6": {
+ "location": "Portland",
+ "species": "ants",
+ "count": 40,
+ },
+ }
-// Write data
-options := influxdb3.WriteOptions{
- Database: database,
-}
-for key := range data {
- point := influxdb3.NewPointWithMeasurement("census").
- AddTag("location", data[key]["location"].(string)).
- AddField(data[key]["species"].(string), data[key]["count"])
+ // convert data to Points
+ points := []*influxdb3.Point{}
+ // start time stamp
+ stamp := time.Now().Add(time.Duration(len(data)) * time.Second * -1)
- if err := client.WritePointsWithOptions(context.Background(), &options, point); err != nil {
- panic(err)
+ for key := range data {
+ points = append(points,
+ influxdb3.NewPointWithMeasurement("census").
+ SetTag("location", data[key]["location"].(string)).
+ SetIntegerField(data[key]["species"].(string),
+ int64(data[key]["count"].(int))).
+ SetTimestamp(stamp))
+ stamp = stamp.Add(time.Second) // Add a second to the stamp
}
- time.Sleep(1 * time.Second) // separate points by 1 second
-}
-
+ // Write data
+ fmt.Printf("Writing %d points\\n", len(points))
+ if err := client.WritePoints(context.Background(),
+ points,
+ influxdb3.WithDatabase(database)); err != nil {
+ panic(err)
+ }
`
return (
@@ -328,7 +335,7 @@ for key := range data {
The program should write data once you run it. After the data is
From 6b621867d8e10ff36d2b267bc98f45f6cecdfddc Mon Sep 17 00:00:00 2001
From: karel rehor
- The following snippet introduces query parameters for the model query above.
- The fixed values "bees" and "ants" are replaced with "species1" and "species2".
- Add this to the end of your{' '}
+ The following snippet introduces query parameters for the model query
+ above. The fixed values "bees" and "ants" are replaced with "species1"
+ and "species2". Add this to the end of your{' '}
main
function: