Comments (9)
I have an actual issue with the fact String()
is used: I support multiple databases and one of them only takes []byte
for UUID.
In the interest of maintaining backwards compatibility, would a patch introducing a global option (yeah, I know...) be accept to return either String()
or byte[]
?
Something along the lines of uuid.ForceBinaryOutputForSQL(true)
from uuid.
A global option would be bad. It would affect every package's use. You never know who might be depending on this. I will admit I am not a database person and this function was implemented by someone who knew more about databases than me. It seems like maybe a new type is needed that embeds a UUID, though it would break the ability to directly access values:
// A UUID Bytes is a UUID whose sql Value function returns a byte slice rather than a string.
type UUIDBytes struct {
UUID
}
func (uuid UUIDBytes) Value() (driver.Value, error) {
return uuid[:], nil
}
from uuid.
@pborman thanks for the reply. Would you propose this new wrapper type to be part of uuid
?
from uuid.
It actually does not need to be part of the UUID package at all. Before adding it to the package it would be good to get some feedback on how easy/hard such a thing would be to use. I think if you never sliced the uuid then you would have no problem. You might also want:
func (uuid UUIDBytes) Bytes() []byte {
return uuid.UUID[:]
}
from uuid.
I am doing some experimentation currently. I'll report my findings here.
Not sure in which context slicing an UUID prior to storing it to the database would make any sense.
from uuid.
It would be more for passing the UUID to something other than a database function, though I guess the code could simply say id.UUID[:] rather than id.Bytes() to get the byte slice.
from uuid.
Bytes() seems to be pretty common in the Go ecosystem - i'll cast a gentle vote in favor of the above as well
from uuid.
I held a similar discussion over gofrs/uuid#48 and a lot has been taken into account. The resulting decision was to not take any action since no solution seems adequate to be adopted long term by a UUID package.
If you all agree with considerations taken over there, feel free to close this issue.
from uuid.
Thanks Ricardo, I think I will close this.
from uuid.
Related Issues (20)
- Equals method HOT 1
- Reference implementaiton for UUID v8 HOT 2
- Is there a method to generate empty UUID v4? HOT 2
- UUID with repeat ending HOT 2
- NullUUID Scan method returns valid true on empty string HOT 2
- [Documentation] uuid.Nil is not documented properly
- `IsZero()` and `ToNullUUID` Helper Functions HOT 1
- panic: uuid: Parse(): invalid UUID length: 0 HOT 1
- Should uuid.Nil marshal to null instead of all zeroes HOT 3
- Make uuid.Nil and other values as a constant HOT 1
- Cannot get the package, connection refused
- uuid.Parse allows invalid UUID's HOT 2
- recommended to add uuid v6 and v7 support HOT 1
- Validate UUID without creating UUID (and underlying byte array)
- Limit permissions for github workflows
- uuid.Parse Function Does Not Handle Leading/Trailing Spaces in UUIDs
- Monotonicity in UUIDv7 HOT 2
- proposal: add func uuid.Compare(a, b UUID) int
- Incorrect uuidv6 implementation HOT 1
- not able to install uuid package HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uuid.