mmzk-typeid-0.1.0.0: A TypeID implementation for Haskell
LicenseMIT
Maintainermmzk1526@outlook.com
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.UUID.V7

Description

UUIDv7 implementation.

UUIDv7 is not currently present in the uuid package, therefore I have to make a quick patch of my own. In the future I will try to add uuid as a dependency and try to use the same interface.

Note that since the specification for v7 is not yet finalised, this module's implementation may change in the future according to the potential adjustments in the specification.

Synopsis

Data type

newtype UUID Source #

A simple wrapper around a ByteString representing a UUIDv7.

Note that the Show instance is for debugging purposes only. To pretty-print a UUIDv7, use toString, toText or toByteString.

Constructors

UUID 

Fields

Instances

Instances details
Show UUID Source # 
Instance details

Defined in Data.UUID.V7

Methods

showsPrec :: Int -> UUID -> ShowS #

show :: UUID -> String #

showList :: [UUID] -> ShowS #

Eq UUID Source # 
Instance details

Defined in Data.UUID.V7

Methods

(==) :: UUID -> UUID -> Bool #

(/=) :: UUID -> UUID -> Bool #

Ord UUID Source # 
Instance details

Defined in Data.UUID.V7

Methods

compare :: UUID -> UUID -> Ordering #

(<) :: UUID -> UUID -> Bool #

(<=) :: UUID -> UUID -> Bool #

(>) :: UUID -> UUID -> Bool #

(>=) :: UUID -> UUID -> Bool #

max :: UUID -> UUID -> UUID #

min :: UUID -> UUID -> UUID #

FromJSON UUID Source # 
Instance details

Defined in Data.UUID.V7

ToJSON UUID Source # 
Instance details

Defined in Data.UUID.V7

UUID generation

nil :: UUID Source #

The nil UUID.

genUUID :: IO UUID Source #

Generate a UUIDv7.

genUUIDs :: Word16 -> IO [UUID] Source #

Generate n UUIDv7s.

It tries its best to generate UUIDs at the same timestamp, but it may not be possible if we are asking too many UUIDs at the same time.

It is guaranteed that the first 32768 UUIDs are generated at the same timestamp.

Encoding & decoding

parseString :: String -> Maybe UUID Source #

Parse a UUIDv7 from its String representation.

The representation is either standard or has no dashes. Does not care about the case of the letters.

parseText :: Text -> Maybe UUID Source #

Parse a UUIDv7 from its string representation as a strict Text.

The representation is either standard or has no dashes. Does not care about the case of the letters.

parseByteString :: ByteString -> Maybe UUID Source #

Parse a UUIDv7 from its string representation as a lazy ByteString.

The representation is either standard or has no dashes. Does not care about the case of the letters.

toString :: UUID -> String Source #

Pretty-print a UUIDv7.

toText :: UUID -> Text Source #

Pretty-print a UUIDv7 to strict Text.

toByteString :: UUID -> ByteString Source #

Pretty-print a UUIDv7 to lazy ByteString.

Miscellaneous helpers

getTime :: UUID -> Word64 Source #

Get the time field (unix_ts_ms) of a UUIDv7.

getEpochMilli :: IO Word64 Source #

Get the current time in milliseconds since the Unix epoch.