Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve createulid #1445

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Used in conjunction with the 'hash' type, this numeric input contributes to the generation of a deterministic ULID by influencing its random component.
Used in conjunction with the `hash` type, this numeric input contributes to the generation of a deterministic ULID by influencing its random component.

only used for hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Similar to 'input1', this string input is utilized only in the 'hash' mode to further seed the ULID's random component, enabling the creation of a deterministic ULID based on the hash of the inputs.
Similar to `input1`, this string input is utilized only in the `hash` mode to further seed the ULID's random component, enabling the creation of a deterministic ULID based on the hash of the inputs.
5 changes: 4 additions & 1 deletion docs/03.reference/01.functions/createulid/_arguments/type.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Specifies the generation mode of the ULID. If not defined, a standard ULID is generated. 'monotonic' ensures ULIDs increase monotonically, suitable for ensuring order in rapid generation scenarios. 'hash' mode generates a ULID based on hashing the provided inputs, useful for creating deterministic identifiers.
Specifies the generation mode of the ULID. If not defined, a standard ULID is generated.

- `monotonic` ensures ULIDs increase monotonically, suitable for ensuring order in rapid generation scenarios.
- `hash` mode generates a ULID based on hashing the provided inputs, useful for creating deterministic identifiers.
9 changes: 9 additions & 0 deletions docs/03.reference/01.functions/createulid/_examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```luceescript+trycf
loop times=3 {
dump( createULID() );
}

loop times=3 {
dump( createUUID() );
}
```
16 changes: 14 additions & 2 deletions docs/03.reference/01.functions/createulid/function.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
---
title: createULID
id: function-createulid
description: Generates a ULID (Universally Unique Lexicographically Sortable Identifier)
related:
categories:
- function-createguid
- function-createuuid
---

Generates a ULID (Universally Unique Lexicographically Sortable Identifier), a 128-bit identifier where the first 48 bits are a timestamp representing milliseconds since the Unix Epoch (1970-01-01), ensuring temporal ordering. The remaining 80 bits are populated by a secure random number generator, contributing to the identifier's uniqueness. The output is a 26-character string in its canonical representation. This function can operate in three modes specified by the 'type' argument: 'empty' for standard ULID generation, 'monotonic' to ensure sequential IDs even in rapid succession, and 'hash' to generate a ULID based on hashed input values.
Generates a ULID (Universally Unique Lexicographically Sortable Identifier), a 128-bit identifier where the first 48 bits are a timestamp representing milliseconds since the Unix Epoch (1970-01-01), ensuring temporal ordering.

The remaining 80 bits are populated by a secure random number generator, contributing to the identifier's uniqueness. The output is a 26-character string in its canonical representation.

This function can operate in three modes specified by the 'type' argument:

- `empty` for standard ULID generation
- `monotonic` to ensure sequential IDs even in rapid succession
- and `hash` to generate a ULID based on hashed input values.

ULIDs are better for insert performance, as they don't create sparse B-Tree indexes like UUIDs, saving disk space