View Source Appwrite.Utils.Id (appwrite v0.2.1)

Helpers for generating resource ID strings compatible with Appwrite's ID format.

Usage

alias Appwrite.Utils.Id

Id.unique()        # "67a3f1b2c0d4e5f6a" — 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 random hex padding.

Functions

custom(id)

@spec custom(String.t()) :: String.t()

Returns the provided custom ID unchanged.

Use this when you want to supply your own ID instead of generating one.

Examples

iex> Appwrite.Utils.Id.custom("my-custom-id")
"my-custom-id"

unique(padding \\ 7)

@spec unique(pos_integer()) :: String.t()

Generates a unique ID by combining a hex-encoded timestamp with random hex padding.

The timestamp portion replicates PHP's uniqid() behaviour (seconds + millisecond fraction, both hex-encoded). The random padding reduces the chance of collision when multiple IDs are generated within the same millisecond.

Parameters

  • padding — number of additional random hex digits appended after the timestamp (default: 7, minimum: 1).

Examples

iex> Appwrite.Utils.Id.unique()
# => something like "67a3f1b2c0001f3a4b5"  (length varies with time)

iex> String.length(Appwrite.Utils.Id.unique(10)) > String.length(Appwrite.Utils.Id.unique(5))
true