def test_ulid_timestamp(): timestamp_values = [0, 1558988971814002421, UINT64_MAX] rnd = 42 for timestamp in timestamp_values: identifier = timestamp.to_bytes(8, "big") + rnd.to_bytes(8, "big") assert ULID(identifier).timestamp == timestamp
def convert_ulid_identifier(data: bytes) -> ULID: return ULID(identifier=data)
@dataclass class Range(Generic[ID]): """Inclusive range used to filter database entries.""" first: ID last: ID def __post_init__(self) -> None: # Because the range is inclusive, the values can be equal if self.first > self.last: raise ValueError("last must be larger or equal to first") LOW_STATECHANGE_ULID = StateChangeID(ULID((0).to_bytes(16, "big"))) HIGH_STATECHANGE_ULID = StateChangeID(ULID((2**128 - 1).to_bytes(16, "big"))) RANGE_ALL_STATE_CHANGES = Range(LOW_STATECHANGE_ULID, HIGH_STATECHANGE_ULID) class Operator(Enum): NONE = "" AND = "AND" OR = "OR" class FilteredDBQuery(NamedTuple): """ FilteredDBQuery is a datastructure that helps form a list of conditions and how they're grouped in order to form more complicated queries