-
Notifications
You must be signed in to change notification settings - Fork 177
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
tweaked scan method to work with most sql drivers // Added Must #44
base: master
Are you sure you want to change the base?
Conversation
@achille-roussel going to leave this one to you :) LMK if you want anything from me on it. |
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.
Thanks for the contribution!
At first sight, I don't think we can merge the code as-is, because it changes the behavior of Scan
in a way that could profoundly break some applications as it changes the way string
values are handled.
I feel like it should be the database's responsibility to ensure that if a column is expected to hold KSUIDs, it should enforce that values are either exactly 20 or 27 bytes, depending on how form the KSUIDs are stored in (binary or text).
Maybe I'm not understanding well the problem, would you happen to have a more detailed example to share?
return i.Scan(string(src)) | ||
} | ||
|
||
return i.Scan(string(src)) |
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.
These recursive calls to Scan
cause heap allocations when packing the string
value into an interface{}
, this is why I have the unexported scan
methods to use internally.
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.
@achille-roussel thanks for your time to review my request!
I see your Point.
return i.Scan(string(src)) | |
return i.UnmarshalText(src) |
Using the UnmarshalText is better. Both functions (scan old, scan new) are now allocating the same. Beside that the new Scan is consuming 2,79% less memory + is slightly faster.
panic(err) | ||
} | ||
return ksuid | ||
} |
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.
Adding this function seems unrelated to the modification of Scan
itself, maybe we can split it in a separate PR?
Stripped the Scan method a 'lil bit. As i had problems to Scan with sqlx library. All tests pass.
UnmarshalText()
,UnmarshalBinary()
are no longer required for Scan.TestSqlScanner()
fromksuid_test.go
is still implemented and PASSSame for
TestSqlValuer()
--- PASS: TestSqlValuer (0.00s)