-
Notifications
You must be signed in to change notification settings - Fork 378
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
feat(uuid): Added support for NullUUID #76
Conversation
Hi, thank you for the solution. This does look like it will resolve a problem, but I think it can be a standalone package rather than built into the base UUID package. What do you think? |
I think that concern was brought up in the issue I mentioned. While this is a rather trivial addition, I think it is warranted in this base package. It would obviously not be appropriate to add it to The other options are to (1) write your own package defining this extra type (which is what I have done), or (2) bring in a separate package, such as go.uuid. With the latter approach you wouldn't necessarily even need I think that's a decent enough case to warrant filling this small feature gap.
|
I think the name of the type would need to be changed. NullUUID sounds like it should be a constant that represents a Null UUID (which some might say is the zero UUID). I am not sure about a good name at the moment, but I do think we need a better name. If there can be a good descriptive name that is not too long then we can add it to the main package. Thanks (sorry for the long delay). |
@pborman how about |
Another option would be to keep it as Edit: the zero UUID already exists as |
The argument about NullString and NullInt64 are good ones when looking at "database/sql". I think adding a statement a statement that this is matching the basic types in "database/sql" would be good. Also, as commented by @msal4, you should lose the type indent.
Due to some recent changes I am hoping I will have more time going forward than I have had in the past for keeping up with this package. |
Oh, would you add a the Marshal/Unmarshal{Text,Binary} methods on this type? This will be helpful for people using JSON. |
9049971
to
cbf519d
Compare
@pborman based on your comment about usage with JSON, I assumed the Marshal functions would return successfully with a |
So I tried the following program https://play.golang.org/p/Rmdq0ukjv73:
And got the following output:
When Marshalling I would expect:
|
@pborman that same code run against the version I just pushed yields:
|
What use is this Valid field for? |
@mvrahden this is how nullable types are implemented in the std lib so it's important as to not confuse users familiar with this pattern. also, it makes sense since you don't want to check if the value is equal to |
@msal4 I see. In that case, it makes sense to stay consistent. Thanks for the clarification 👍 |
Over all this looks good. I will merge it and then clean up a few things and then cut a new release with the most recent changes. Thank you. |
Per the discussion in #54, this introduces a
NullUUID
type to the package that works like other nullable types in thedatabase/sql
package. Figured I'd just get the PR out while I'm playing around in this space.