mareek / UUIDNext

A fast and modern .NET library to generate UUID/GUID that are either sequential and database friendly (versions 7), name based (versions 5) or random (version 4).
BSD Zero Clause License
225 stars 13 forks source link

Add a way to create an UUIDv7 for a specific timestamp #16

Open mareek opened 3 weeks ago

mareek commented 3 weeks ago

Things to keep in mind :

See .NET 9's Guid.CreateVersion7(DateTimeOffset) and #14 for inspiration

timstokman commented 2 weeks ago

One thing that would be very nice is, besides support for the time component, to also be able to determine the random component. This is pretty important for database queries.

Suppose I have a UUIDv7 Id field. It's indexed/partitioned/sharded based on the Id field. I want to query the database for data for the last day, without creating additional indexes. Then being able to construct a query like this:

SELECT * FROM Id >= lowerBoundry

would be nice, where the random component for the lower boundary is initialised to zero. To support these types of queries initializing the random component to the maximum or minimum value needs to be supported in the API.