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

Update copied changes from sqlds #862

Merged
merged 3 commits into from
Jan 22, 2024
Merged

Update copied changes from sqlds #862

merged 3 commits into from
Jan 22, 2024

Conversation

njvrzm
Copy link
Contributor

@njvrzm njvrzm commented Jan 18, 2024

What this PR does / why we need it:
Functionality from sqlds/macros.go and sqlds/query.go was brought into this repo's sqlutil as part of https://github.com/grafana/oss-plugin-partnerships/issues/94. Since then some features and bugfixes have been added to the originals. These changes need to be brought in to sqlutil as well to bring the functionality here up to date, so sqlds can be migrated to use this library instead of its own versions (grafana/sqlds#85).

For this PR I've tried as much as possible to copy the sqlds code over unchanged. #863 applies some refactoring and fixes a couple of bugs.

Which issue(s) this PR fixes:

Addresses #858.

@njvrzm njvrzm self-assigned this Jan 18, 2024
@njvrzm njvrzm force-pushed the 858-changes_from_sqlds branch 3 times, most recently from 161bbd3 to ce99188 Compare January 18, 2024 10:51
@njvrzm njvrzm linked an issue Jan 18, 2024 that may be closed by this pull request
@njvrzm njvrzm marked this pull request as ready for review January 18, 2024 11:23
@njvrzm njvrzm requested review from a team as code owners January 18, 2024 11:23
@njvrzm njvrzm requested review from gabor, yesoreyeram, zoltanbedi, wbrowne, marefr, xnyo and gwdawson and removed request for a team, zoltanbedi, wbrowne, marefr, xnyo and yesoreyeram January 18, 2024 11:23
Copy link
Contributor

@gabor gabor left a comment

Choose a reason for hiding this comment

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

LGTM 👍

if err != nil {
return rawSQL, err
}

rawSQL = strings.ReplaceAll(rawSQL, match[0], res)
rawSQL = strings.ReplaceAll(rawSQL, match.Name, res)
Copy link
Contributor

Choose a reason for hiding this comment

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

random note, this is not part of the diff.. here we use ReplaceAll().
in sqlds, it's Replace():

https://github.com/grafana/sqlds/blob/dda2dc0a54b128961fc9f7885baabf555f3ddfdc/macros.go#L258

what do you think, which one is "more correct"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I actually made the change intentionally in my original PR; this time around I forgot, but then the linter in this repo told me to change it! Looks like this comes from gocritic:

❯ mage lint
data/sqlutil/macros.go:215:13: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(rawSQL, match.full, res, -1)` (gocritic)
			rawSQL = strings.Replace(rawSQL, match.full, res, -1)
			         ^
Error: running "golangci-lint run ./..." failed with exit code 1

I also prefer ReplaceAll as I think it makes the intention more clear, but it's a pretty minor thing.

@njvrzm njvrzm merged commit d36c501 into main Jan 22, 2024
4 checks passed
@njvrzm njvrzm deleted the 858-changes_from_sqlds branch January 22, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Update functionality brought in from sqlds
2 participants