Appwrite. Utils. Id
(appwrite v1.0.0)
View Source
Helpers for generating resource ID strings compatible with Appwrite's ID format.
Usage
alias Appwrite.Utils.Id
Id.unique() # "67a3f1b20001f3a4b5" — timestamp + random padding
Id.unique(10) # longer padding
Id.custom("myId") # pass-through a caller-supplied ID
Summary
Functions
Returns the provided custom ID unchanged.
Generates a unique ID by combining a hex-encoded timestamp with cryptographically-random hex padding.
Functions
Returns the provided custom ID unchanged.
Use this when you want to supply your own ID rather than having one generated.
Examples
iex> Appwrite.Utils.Id.custom("my-custom-id")
"my-custom-id"
@spec unique(pos_integer()) :: String.t()
Generates a unique ID by combining a hex-encoded timestamp with cryptographically-random hex padding.
The timestamp portion mirrors PHP's uniqid() (seconds + millisecond
fraction, both hex-encoded). Random padding uses :crypto.strong_rand_bytes/1
so successive IDs generated in the same millisecond are still unguessable.
Parameters
padding— extra random hex bytes appended after the timestamp. Default7. Each byte produces two hex characters, sopadding: 7adds 14 hex characters.
Examples
iex> id = Appwrite.Utils.Id.unique()
iex> is_binary(id) and byte_size(id) > 0
true
iex> String.length(Appwrite.Utils.Id.unique(10)) > String.length(Appwrite.Utils.Id.unique(3))
true