There should be an UUID class (feature proposal)

Hi!

Currently, Rails represents UUIDs as regular strings. Active Support defines

Digest::UUID, but it’s a module with four functions which all return strings

containing UUIDs in a human-readable form.

I propose representing UUIDs as instances of a brand new UUID class to Active

Support, alternatively turning existing Digest::UUID module into a class for

this purpose.

Why I consider it beneficial:

Oh, I forgot to mention that I am willing to implement this feature after current discussion.

Any reason you can’t just store and/or compare uuid’s all upcased?

A valid uuid matches /\A[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\z/i

but if you want to compare two, for whatever reason, only the case should matter, no?

One reason is space. A string representation of UUID is 36 characters long (with dashes), and the number it represents is 16 bytes long. Obviously, it’s very unlikely that one would run out of disk space on your database server because of that. However UUID columns are often indexed, they can even serve as table’s primary key. And for indexes, size matters. The bigger portion of index you can keep in memory, the better it performs.

Another reason is database-agnosticism. One can use the uuid type in config/schema.rb, but then this file won’t work with other databases than PostgreSQL. I see no good reason for that.