Skip to content

Add FromField and ToField instance for Data.UUID#89

Closed
mkoppmann wants to merge 1 commit into
nurpax:masterfrom
mkoppmann:add-instances-for-uuid
Closed

Add FromField and ToField instance for Data.UUID#89
mkoppmann wants to merge 1 commit into
nurpax:masterfrom
mkoppmann:add-instances-for-uuid

Conversation

@mkoppmann

Copy link
Copy Markdown
Contributor

The implementation is based on postgresql-simple(FromField, ToField). uuid-types is used because it contains fewer transitive dependencies, but uuid is used as a dependency for the test case.

This fixes #62.

@kmicklas

Copy link
Copy Markdown
Contributor

I'm somewhat concerned with this instance since it isn't really canonical. I've used orphan instances for UUID, except encoding to binary blobs instead of text for compactness, for example.

@mkoppmann

Copy link
Copy Markdown
Contributor Author

You’re right. That’s why I just copied what postgresql-simple did just to be consistent at least.
If this PR isn’t going to be merged, I will accept that of course and just continue to provide my own newtype wrapper in my codebase :)

@kmicklas

kmicklas commented Feb 5, 2021

Copy link
Copy Markdown
Contributor

What do you mean by consistent? Postgres has a native UUID type so it doesn't have to a make a choice between string/blob.

@mkoppmann

Copy link
Copy Markdown
Contributor Author

Oh, true. I now see the problem with this too. So either we choose a default instance and people who want a binary implementation have to use a newtype, or we don’t define an instance at all.

@emberdart

Copy link
Copy Markdown

Although it's less space-saving, I suspect that the text encoding is viewed as making more sense because it can be directly queried in a textual manner.

@malteneuss

malteneuss commented Apr 19, 2025

Copy link
Copy Markdown

Same as in #62:
As there are basically two valuable encodings (as binary BLOB for performance, and TEXT for human readability in e.g. CLI), would it be possible to add both encodings with BLOB as the default to be fast by default like Postgres and popular Rust libraries like rusqlite do, and a newtype wrapper like TextUUID for textual representations?

Having UUIDv7 soon in haskell-hvr/uuid#87 makes the UUID type even more appealing in databases so that out-of-the-box support would be great.

@mkoppmann mkoppmann closed this by deleting the head repository Jun 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add FromField instance for UUID

4 participants