Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update onboarding steps for Go v3 client #6987

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 39 additions & 59 deletions src/homepageExperience/components/steps/go/ExecuteQuerySql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,70 +21,48 @@ FROM 'census'
WHERE time >= now() - interval '1 hour'
AND ('bees' IS NOT NULL OR 'ants' IS NOT NULL)`

const querySnippet = `// Execute query
query := \`SELECT *
FROM 'census'
WHERE time >= now() - interval '1 hour'
AND ('bees' IS NOT NULL OR 'ants' IS NOT NULL)\`
const querySnippet = ` // Execute query with parameters
query := \`SELECT *
FROM 'census'
WHERE time >= now() - interval '1 hour'
AND ($species1 IS NOT NULL OR $species2 IS NOT NULL)\`

queryOptions := influxdb3.QueryOptions{
Database: database,
}
iterator, err := client.QueryWithOptions(context.Background(), &queryOptions, query)
iterator, err := client.QueryWithParameters(context.Background(),
query, influxdb3.QueryParameters{
"species1": "bees",
"species2": "ants",
},
influxdb3.WithDatabase(database))

if err != nil {
panic(err)
}
if err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also curious about the whitespace here, looks like the number of spaces in a tab has changed, is that maintained across all snippets in the go onboarding?

}

for iterator.Next() {
value := iterator.Value()
val2int := func(v interface{}) int64 {
if v == nil {
return 0
}
return v.(int64)
}

for iterator.Next() {
value := iterator.Value()

location := value["location"]
ants := value["ants"]
bees := value["bees"]
fmt.Printf("in %s are %d ants and %d bees\\n", location, ants, bees)
}
location := value["location"]
ants := val2int(value["ants"])
bees := val2int(value["bees"])
ts := value["time"].(time.Time)
fmt.Printf("At %s in %s there were %d ants and %d bees\\n",
ts.Format(time.RFC3339), location, ants, bees)
}
`

const resultPreviewSnippet = `RECORD BATCH
[
{
"ants": null,
"bees": 23,
"location": "Klamath",
"time": "2023-02-08 00:50:22.729692187"
},
{
"ants": null,
"bees": 28,
"location": "Klamath",
"time": "2023-02-08 00:50:25.22003343"
},
{
"ants": null,
"bees": 29,
"location": "Klamath",
"time": "2023-02-08 00:50:27.5276304"
},
{
"ants": 40,
"bees": null,
"location": "Portland",
"time": "2023-02-08 00:50:21.465572125"
},
{
"ants": 30,
"bees": null,
"location": "Portland",
"time": "2023-02-08 00:50:23.866994344"
},
{
"ants": 32,
"bees": null,
"location": "Portland",
"time": "2023-02-08 00:50:26.42849497"
}
]`
const resultPreviewSnippet = `At 2024-12-13T13:33:13Z in Klamath there were 0 ants and 28 bees
At 2024-12-13T13:33:15Z in Klamath there were 0 ants and 29 bees
At 2024-12-13T13:33:17Z in Klamath there were 0 ants and 23 bees
At 2024-12-13T13:33:14Z in Portland there were 32 ants and 0 bees
At 2024-12-13T13:33:16Z in Portland there were 40 ants and 0 bees
At 2024-12-13T13:33:18Z in Portland there were 30 ants and 0 bees`

return (
<>
Expand All @@ -104,7 +82,9 @@ for iterator.Next() {
with a "census" measurement and either "bees" or "ants" fields.
</p>
<p>
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{' '}
<code className="homepage-wizard--code-highlight">main</code> function:
</p>
<CodeSnippet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const InstallDependenciesSql: FC = () => {
<CodeSnippet
language="properties"
onCopy={logCopyInstallCodeSnippet}
text="go get github.com/InfluxCommunity/influxdb3-go"
text="go get github.com/InfluxCommunity/influxdb3-go/v2"
/>
<p>
You'll need to have{' '}
Expand Down
3 changes: 2 additions & 1 deletion src/homepageExperience/components/steps/go/WriteData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const WriteDataComponent = (props: OwnProps) => {
onSelectBucket(bucket.name)
}, [bucket, onSelectBucket])

const codeSnippet = `org := "${org.name}"
const codeSnippet = `// FOO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the // FOO line is the only thing changed here, is that for consistency?

org := "${org.name}"
bucket := "${bucket.name}"
writeAPI := client.WriteAPIBlocking(org, bucket)
for value := 0; value < 5; value++ {
Expand Down
103 changes: 55 additions & 48 deletions src/homepageExperience/components/steps/go/WriteDataSql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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{}{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious to see what effect this whitespace has on the snippet

"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 (
Expand Down Expand Up @@ -328,7 +335,7 @@ for key := range data {
<CodeSnippet
language="properties"
onCopy={logCopyRunCodeSnippet}
text="go run ./main.go"
text="go mod tidy && go run ./main.go"
/>
<p>
The program should write data once you run it. After the data is
Expand Down
Loading