Skip to content

Commit

Permalink
improve createulid (#1445)
Browse files Browse the repository at this point in the history
* improve createulid

* Update input1.md
  • Loading branch information
zspitzer authored Jul 10, 2024
1 parent df6f8ca commit 809d759
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
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

0 comments on commit 809d759

Please sign in to comment.