-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add some default macros #45
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Can we add few lines in README about this? otherwise will become difficult to track these changes in future.
macros.go
Outdated
to = query.TimeRange.To.UTC().Format(time.RFC3339) | ||
) | ||
|
||
return fmt.Sprintf("%s BETWEEN '%s' AND '%s'", column, from, to), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think all the databases support BETWEEN
. Some require syntax like timefield >= starttime AND timefield < endtime
. Wondering what is the most common approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems to be part of the standard but that should also work.
macros.go
Outdated
return "", errors.WithMessagef(ErrorBadArgumentCount, "expected 1 argument, received %d", len(args)) | ||
} | ||
|
||
return fmt.Sprintf("%s > '%s'", args[0], query.TimeRange.From.UTC().Format(time.RFC3339)), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be >=
instead >
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's worth continuing the discussion. I'm skeptical that any kind of default macro is going to work for every database.
I wonder if all databases even support comparing times with > or <.
Perhaps for those that don't, they could overwrite the key in the DefaultMacros map? If that's a possible use case we should document that :)
Yes, my intention here is to add macros that work in most databases (for example the |
Good point. I will add that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @andresmgot!
Drone keeps not building my PRs :/ checked the tests locally and it passes so merging this to unblock me. |
Fixes #43
I have added default macros and a suggested implementation (that should work for any SQL server). It's expected from the data sources to re-implement them if necessary, to adjust to their needs.
The goal is to set a common ground so all the SQL datasources implement at least a common set of macros following the pattern defined here.