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

feat: SQL query with named parameters #56

Merged
merged 14 commits into from
Feb 27, 2024
Merged

Conversation

alespour
Copy link
Contributor

@alespour alespour commented Jan 26, 2024

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:

  • WithDatabase
  • WithQueryType

WriteOption:

  • WithDatabase
  • WithPrecision
  • WithGzipThreshold
  • WithDefaultTags

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

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional
  • Sign CLA (if not already signed)

@bednar bednar marked this pull request as ready for review February 27, 2024 08:31
Copy link

codecov bot commented Feb 27, 2024

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 ⚠️
influxdb3/query.go 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -87,21 +108,28 @@ func (c *Client) Query(ctx context.Context, query string) (*QueryIterator, error
// Returns:
// - A custom iterator (*QueryIterator) that can also be used to get raw flightsql reader.
// - An error, if any.
//
// Deprecated: use Query with QueryOption options.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the Deprecation message could be more precise. e.g. "Deprecated: use Query with variadic QueryOption options". The deprecated method itself has a similar argument with a pointer to QueryOptions. At first glance it can be a bit confusing.

Copy link
Member

Choose a reason for hiding this comment

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

The message is updated.

@@ -59,7 +61,17 @@ func (c *Client) WritePoints(ctx context.Context, points ...*Point) error {
//
// Returns:
// - An error, if any.
//
// Deprecated: use WritePoints with WriteOption options.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too maybe the message could be more specific. e.g. "Deprecated: use WritePoints with variadic WriteOption options"

Copy link
Member

Choose a reason for hiding this comment

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

The message is updated.

Copy link
Contributor

@karel-rehor karel-rehor left a comment

Choose a reason for hiding this comment

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

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"

@bednar
Copy link
Member

bednar commented Feb 27, 2024

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.

@bednar bednar merged commit 423a7cd into main Feb 27, 2024
11 checks passed
@bednar bednar deleted the feat/sql-named-parameters branch February 27, 2024 19:34
@bednar bednar added this to the 0.6.0 milestone Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants