-
Notifications
You must be signed in to change notification settings - Fork 115
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
Parametrically build query, rather than creating large string #146
Comments
I understand this is in discussion for other InfluxDB 2 clients - is this in consideration for Golang as well? |
@JoshuaKahn, the first proposal was that this should supported directly by the server, see InfluxDB issue #16109. However, as it looks like it will not be implemented on the server side, this features in on the backlog of all official clients, including Go, and it has been already implemented in the InfluxDB javascript client. |
According to the docs Parametrized Flux queries are supported now. You can read more in API docs. Would maintainers accept the PR which will add support of it to Go SDK? I'll be happy to add something like this. Probably the simplest solution which does not break anything is to add two additional methods to interface influxdb-client-go/api/query.go Lines 45 to 51 in 5b2f2a3
which will look like that QueryParametrizedRaw(ctx context.Context, query string, params map[string]interface{}, dialect *domain.Dialect) (string, error)
QueryParametrized(ctx context.Context, query string, params map[string]interface{}) (*QueryTableResult, error) and later maybe refactor as part of #205 to have parametrized queries available as default way of doing it. |
@programmer04, thanks for rising this. However, this feature is part of the InfluxDB 2 Cloud, but it doesn't work on OSS yet. So, it cannot be part of public API yet. To your design: However, the better solution seems to be by adding variadic params to current functions:
|
Currently, influxdb-client-go (and other InfluxDB 2.0 client libraries) uses a string to query an InfluxDB database. This works well if the query is static, but if the query is dynamic, it can lead to some problems if IDs of measurements/fields/names or values of time have to be dynamically entered into the query. Additionally, if a user was given control over what some measurements/fields/names are called at runtime, it could lead to potential SQL injection.
Ideally, it should be possible to parametrically build a query out of variables or values; for example, calling a func/type to create a name or filter.
The text was updated successfully, but these errors were encountered: