-
-
Notifications
You must be signed in to change notification settings - Fork 4
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 type-safety in operators #8
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pull Request Test Coverage Report for Build 4636597426
💛 - Coveralls |
3396308
to
d194c07
Compare
d194c07
to
318fd84
Compare
4c12ed4
to
2f49682
Compare
6337601
to
b4da5c2
Compare
b4da5c2
to
cb3c4a1
Compare
0da9fdd
to
307a3d7
Compare
System-Glitch
commented
Apr 6, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #7
Type safety
Added type-safety. The operators now generate valid SQL matching the column's data type. The data type is determined by the new struct tag
fieldType
. If not provided, the type will be determined from GORM's data type. If GORM's data type is a custom type or a type that is not directly supported by this library, the type will fall back to-
(unsupported).See the updated README for more details.
Breaking change
This change breaks custom operators: the function signature changed.
You may need to update your models by adding the new
fieldType
struct tag on non-native types (such as arrays and enum types). Structures implementingdriver.Valuer
should work without needing for a change.Fields having a custom database type set (
gorm:"type:DOUBLE PRECISION"
for example) should work too as the type detection is based onGORMDataType
and not on the actualDataType
.Types from the
guregu/null
library should work without having to add thefieldType
tag since they implementdriver.Valuer
.You may also need to update computed columns that would return a type that doesn't exactly match the struct field. This is common when working with JSON nested fields. Database engines usually always return text types from JSON operations, which is incompatible with numbers.