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

make GetDBConnectionFromQuery public #71

Merged
merged 2 commits into from Sep 26, 2022
Merged

Conversation

iwysiu
Copy link
Contributor

@iwysiu iwysiu commented Sep 23, 2022

I merged the other commit before realizing that there were other comments on grafana-aws-sdk that related to this package.

Fixes #66

Copy link
Collaborator

@sunker sunker left a comment

Choose a reason for hiding this comment

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

LGTM

datasource.go Outdated
@@ -138,36 +138,36 @@ func (ds *SQLDatasource) QueryData(ctx context.Context, req *backend.QueryDataRe

}

func (ds *SQLDatasource) getDBConnectionFromQuery(q *Query, datasourceUID string) (string, dbConnection, error) {
func (ds *SQLDatasource) GetDBConnectionFromQuery(q *Query, datasourceUID string) (string, *sql.DB, *backend.DataSourceInstanceSettings, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

mmh, from the usage I see here, you are only interested on getting the *sql.DB, not the internal key and the instance settings. I would create two different functions here: GetDBFromQuery that returns what you want and getSettings that returns the rest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree with that a bit, since the logic for getting the *sql.DB and the instance settings is so intertwined that separate GetDBFromQuery and getSettings functions would be basically repeated code. I could see the logic in making GetDBConnectionFromQuery private again and adding GetDBFromQuery that wraps it and just returns the *sql.DB if we want to reduce the exposed information.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, I am not saying that we should repeat code, I am mostly worried that you will be exposing this method with unnecessary things and once you expose it, any change to it would be a breaking change.

I have not taken a deep look to this code so up to you for the final solution, you can either do that wrapper or move common stuff to a different function so you call it from both functions, the external and the internal.

@iwysiu iwysiu merged commit f5e7816 into main Sep 26, 2022
@iwysiu iwysiu deleted the public-getDBConnectionFromQuery branch September 26, 2022 17:33
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.

Expose functionality for long running queries
3 participants