InfluxCommunity / influxdb3-go

The go package that provides a simple and convenient way to interact with InfluxDB 3.
https://pkg.go.dev/github.com/InfluxCommunity/influxdb3-go
MIT License
21 stars 11 forks source link

feat: SQL query with named parameters #56

Closed alespour closed 4 months ago

alespour commented 5 months ago

Closes #55

Proposed Changes

This PR add supports for named parameters in the query API QueryWithParameters(context.Context, string, QueryParameters, ...QueryOption)

client.QueryWithParameters(ctx,
    "SELECT a, b, c FROM my_table WHERE id = $id AND name = $name",
    influxdb3.QueryParameters{
      "id", 1,
      "name", "test",
    }
)

Breaking changes

Changed existing Query* and Write* methods from

Query(context.Context, string)
QueryWithOptions(context.Context, string, *QueryOptions)

Write(context.Context, []byte)
WriteWithOptions(context.Context, *WriteOptions, []byte)
WriteData(context.Context, ...*interface{})
WriteDataWithOptions(context.Context, *WriteOptions, ...*interface{})
WritePoints(context.Context, ...*Points)
WritePointsWithOptions(context.Context, *WriteOptions, ...*Points)

to

Query(context.Context, string, ...QueryOption)

Write(context.Context, []byte, ...WriteOption)
WriteData(context.Context, []*interface{}, ...WriteOption)
WritePoints(context.Context, []*Points, ...WriteOption)

where available options are

QueryOption:

WriteOption:

Example:

client.Write(ctx,
    []byte("my_table,name=miracle,id=1 a=0,b=1,c-2 1706284020"),
    influxdb3.WithPrecision(lineprotocol.Second)
)

client.Query(ctx,
    "SELECT a, b, c FROM my_table WHERE id = 1 AND name = miracle",
    influxdb3.WithDatabase("db-miracles"))
)

Checklist

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 92.59259% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 83.09%. Comparing base (a9da0b1) to head (f6916ef).

Files Patch % Lines
influxdb3/write.go 83.33% 4 Missing and 1 partial :warning:
influxdb3/query.go 92.30% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #56 +/- ## ========================================== - Coverage 83.31% 83.09% -0.22% ========================================== Files 11 12 +1 Lines 935 994 +59 ========================================== + Hits 779 826 +47 - Misses 128 138 +10 - Partials 28 30 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

bednar commented 4 months ago

Tried new features and some old in ad hoc tests here https://github.com/bonitoo-io/influxdb3-client-tests/tree/main/go-client/release-0.6.0.

While these covered the core of the golden path, nothing unexpected occurred and results look sound.

Nit pick: As mentioned at points in review, the message on deprecated methods can be a bit confusing at first glance. Perhaps it could be improved by being more specific.

For example.

  • current: "Deprecated: use Query with WithQueryOptions option"
  • suggested: "Deprecated: use Query with variadic QueryOptions option"

The messages are updated.