|
6 | 6 |
|
7 | 7 | A Prisma extension that automatically adds prefixed IDs to your models. This package allows you to configure custom prefixes for your models and even customize how the IDs are generated.
|
8 | 8 |
|
9 |
| -## Why nanoid instead of UUID v4? |
10 |
| - |
11 |
| -This package uses [nanoid](https://github.com/ai/nanoid) for ID generation instead of UUID v4 for several reasons: |
12 |
| - |
13 |
| -1. **Better Collision Resistance**: While UUID v4 has a 122-bit random component, nanoid with 24 characters (using 36 possible characters) provides approximately 128 bits of entropy, making it even more collision-resistant than UUID v4. |
14 |
| - |
15 |
| -2. **Smaller Size**: A UUID v4 is 36 characters long (including hyphens), while a nanoid with 24 characters is more compact. When combined with a prefix (e.g., `usr_`), the total length is still shorter than a UUID v4. |
16 |
| - |
17 |
| -3. **URL-Safe**: nanoid uses URL-safe characters by default, making it suitable for use in URLs without encoding. |
18 |
| - |
19 |
| -4. **Customizable**: nanoid allows you to customize the alphabet and length, giving you more control over the ID format. |
20 |
| - |
21 |
| -5. **Better Performance**: nanoid is optimized for performance and generates IDs faster than UUID v4. |
22 |
| - |
23 |
| -For example, with a 24-character nanoid: |
24 |
| -- The chance of a collision is approximately 1 in 2^128 (same as UUID v4) |
25 |
| -- The ID length is 24 characters + prefix length (e.g., `usr_abc123...`) |
26 |
| -- The alphabet includes 36 characters (0-9, a-z), making it both readable and compact |
27 |
| - |
28 | 9 | ## Installation
|
29 | 10 |
|
30 | 11 | ```bash
|
@@ -122,6 +103,25 @@ The `idGenerator` function should:
|
122 | 103 |
|
123 | 104 | The default generator uses nanoid with a 24-character length and alphanumeric characters.
|
124 | 105 |
|
| 106 | +## Why nanoid instead of UUID v4? |
| 107 | + |
| 108 | +This package uses [nanoid](https://github.com/ai/nanoid) for ID generation instead of UUID v4 for several reasons: |
| 109 | + |
| 110 | +1. **Better Collision Resistance**: While UUID v4 has a 122-bit random component, nanoid with 24 characters (using 36 possible characters) provides approximately 128 bits of entropy, making it even more collision-resistant than UUID v4. |
| 111 | + |
| 112 | +2. **Smaller Size**: A UUID v4 is 36 characters long (including hyphens), while a nanoid with 24 characters is more compact. When combined with a prefix (e.g., `usr_`), the total length is still shorter than a UUID v4. |
| 113 | + |
| 114 | +3. **URL-Safe**: nanoid uses URL-safe characters by default, making it suitable for use in URLs without encoding. |
| 115 | + |
| 116 | +4. **Customizable**: nanoid allows you to customize the alphabet and length, giving you more control over the ID format. |
| 117 | + |
| 118 | +5. **Better Performance**: nanoid is optimized for performance and generates IDs faster than UUID v4. |
| 119 | + |
| 120 | +For example, with a 24-character nanoid: |
| 121 | +- The chance of a collision is approximately 1 in 2^128 (same as UUID v4) |
| 122 | +- The ID length is 24 characters + prefix length (e.g., `usr_abc123...`) |
| 123 | +- The alphabet includes 36 characters (0-9, a-z), making it both readable and compact |
| 124 | + |
125 | 125 | ## License
|
126 | 126 |
|
127 | 127 | MIT
|
0 commit comments