ahawker / ulid

Universally Unique Lexicographically Sortable Identifier (ULID) in Python 3
Apache License 2.0
695 stars 42 forks source link

Values for range queries #457

Closed neg3ntropy closed 4 years ago

neg3ntropy commented 4 years ago

To do range selection on time with ULIDs one needs to generate values with the lowest/highest possible randomness.

While this is doable with some effort, I feel it should be offered by the API. For example:

uilid.from_timestamp(timestamp, randomness=ulid.MIN_RANDOM)
ahawker commented 4 years ago

@neg3ntropy Thanks for the request, it makes sense to me. Let me think about implementation details a bit and how the API should change before taking a stab at it.

ahawker commented 4 years ago

I've got a WIP PR up that should address this in #469.

It adds a new method, create for building ULID instances when you have both parts.

timestamp = time.time()
value = ulid.create(timestamp, ulid.MAX_RANDOMNESS)

I'm not sure if I like this more than using from_timestamp and from_randomness with optional kwargs for the other parts, was just trying to avoid more branching logic and handle the case where the caller has both parts of a ULID instead of just one. I'll think about this some more.