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

fix: uniform client API #31

Merged
merged 20 commits into from
Aug 10, 2023
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

1. [#30](https://github.com/InfluxCommunity/influxdb3-go/pull/30): Add custom HTTP headers support

### Breaking Changes

1. [#31](https://github.com/InfluxCommunity/influxdb3-go/pull/31): Changed package to `influxdb3`.
Renamed config types and some options.

## 0.1.0 [2023-06-09]

- initial release of new client version
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,21 @@ import (
)
```

Create `influx.Client` with `New` function. Make sure to `Close` client after with `defer` keyword.
Create `influxdb3.Client` with `New` function. Make sure to `Close` client after with `defer` keyword.

```go
url := os.Getenv("INFLUXDB_URL")
token := os.Getenv("INFLUXDB_TOKEN")
database := os.Getenv("INFLUXDB_DATABASE")

// Create a new client using an InfluxDB server base URL and an authentication token
client, err := influx.New(influx.Configs{
HostURL: url,
AuthToken: token,
client, err := influxdb3.New(influxdb3.ClientConfig{
Host: url,
Token: token,
Database: database,
})
// Close client at the end and escalate error if present
defer func (client *influx.Client) {
defer func (client *influxdb3.Client) {
err := client.Close()
if err != nil {
panic(err)
Expand All @@ -107,7 +108,7 @@ The `client` can be now used to insert data using [line-protocol](https://docs.i

```go
line := "stat,unit=temperature avg=23.5,max=45.0"
err = client.Write(context.Background(), database, []byte(line))
err = client.Write(context.Background(), []byte(line))
```

Fetch data using FlightSQL query and print result.
Expand All @@ -122,7 +123,7 @@ query := `
"unit" IN ('temperature')
`;

iterator, err := client.Query(context.Background(), database, query, nil)
iterator, err := client.Query(context.Background(), query)

if err != nil {
panic(err)
Expand Down
25 changes: 13 additions & 12 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"time"

"github.com/InfluxCommunity/influxdb3-go/influx"
"github.com/InfluxCommunity/influxdb3-go/influxdb3"
)

func main() {
Expand All @@ -16,40 +16,41 @@ func main() {
database := os.Getenv("INFLUXDB_DATABASE")

// Create a new client using an InfluxDB server base URL and an authentication token
client, err := influx.New(influx.Configs{
HostURL: url,
AuthToken: token,
client, err := influxdb3.New(influxdb3.ClientConfig{
Host: url,
Token: token,
Database: database,
})

if err != nil {
panic(err)
}
// Close client at the end and escalate error if present
defer func(client *influx.Client) {
defer func(client *influxdb3.Client) {
err := client.Close()
if err != nil {
panic(err)
}
}(client)

// Create point using full params constructor
p := influx.NewPoint("stat",
p := influxdb3.NewPoint("stat",
map[string]string{"unit": "temperature"},
map[string]interface{}{"avg": 24.5, "max": 45.0},
time.Now())
// write point synchronously
err = client.WritePoints(context.Background(), database, p)
err = client.WritePoints(context.Background(), p)
if err != nil {
panic(err)
}
// Create point using fluent style
p = influx.NewPointWithMeasurement("stat").
p = influxdb3.NewPointWithMeasurement("stat").
AddTag("unit", "temperature").
AddField("avg", 23.2).
AddField("max", 45.0).
SetTimestamp(time.Now())
// write point synchronously
err = client.WritePoints(context.Background(), database, p)
err = client.WritePoints(context.Background(), p)
if err != nil {
panic(err)
}
Expand All @@ -62,13 +63,13 @@ func main() {
Time time.Time `lp:"timestamp"`
}{"stat", "temperature", 22.3, 40.3, time.Now()}
// Write point
err = client.WriteData(context.Background(), database, sensorData)
err = client.WriteData(context.Background(), sensorData)
if err != nil {
panic(err)
}
// Or write directly line protocol
line := fmt.Sprintf("stat,unit=temperature avg=%f,max=%f", 23.5, 45.0)
err = client.Write(context.Background(), database, []byte(line))
err = client.Write(context.Background(), []byte(line))
alespour marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
panic(err)
}
Expand All @@ -83,7 +84,7 @@ func main() {
"unit" IN ('temperature')
`

iterator, err := client.Query(context.Background(), database, query)
iterator, err := client.Query(context.Background(), query)

if err != nil {
panic(err)
Expand Down
95 changes: 0 additions & 95 deletions influx/client_e2e_test.go

This file was deleted.

Loading