Skip to content

Commit

Permalink
add length option to nanoid (#6508)
Browse files Browse the repository at this point in the history
* add length option to nanoid

* add length option to nanoid

* Update content/200-orm/500-reference/100-prisma-schema-reference.mdx
  • Loading branch information
nikolasburk authored Dec 10, 2024
1 parent 142c975 commit da867ff
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions content/200-orm/500-reference/100-prisma-schema-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3150,7 +3150,7 @@ model User {

### `nanoid()`

Generated values based on the [Nano ID](https://github.com/ai/nanoid) spec.
Generated values based on the [Nano ID](https://github.com/ai/nanoid) spec. `nanoid()` accepts an integer value between 2 and 255 that specifies the _length_ of the generate ID value, e.g. `nanoid(16)` will generated ID with 16 characters. If you don't provide a value to the nanoid() function, the default value is 21.

:::info

Expand All @@ -3173,7 +3173,7 @@ There are two main differences between Nano ID and UUID v4:

#### Examples

##### Generate `nanoid()` values as IDs
##### Generate `nanoid()` values with 21 characters as IDs

<TabbedContent code>
<TabItem value="Relational databases">
Expand All @@ -3198,6 +3198,32 @@ model User {
</TabItem>
</TabbedContent>

##### Generate `nanoid()` values with 16 characters as IDs

<TabbedContent code>
<TabItem value="Relational databases">

```prisma
model User {
id String @id @default(nanoid(16))
name String
}
```

</TabItem>
<TabItem value="MongoDB">

```prisma
model User {
id String @id @default(nanoid(16)) @map("_id")
name String
}
```

</TabItem>
</TabbedContent>




### `now()`
Expand Down

0 comments on commit da867ff

Please sign in to comment.