Skip to content

Commit

Permalink
add length option to nanoid
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Dec 9, 2024
1 parent 142c975 commit de87215
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()` also accepts an integer value that indicates the target _length_ of the generated ID value, e.g. `nanoid(16)`. 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 de87215

Please sign in to comment.