P
Prisma•3d ago
Uncle

cuid2 length

What is the length of the generated cuid(2) ids? I'm looking to validate them via zod.
6 Replies
Prisma AI Help
Prisma AI Help•3d ago
You opted for speed from this bot. Let's conjure up an answer right now! Based on the knowledge sources provided, I can answer your question about the length of generated cuid(2) IDs in Prisma. According to the Prisma schema reference, when using cuid(2), the length of the generated ID is not explicitly specified. However, it's mentioned that a safe field size for cuid() is 30 characters to allow for very large values. For validation purposes with Zod, you might want to set a maximum length of 30 characters to be on the safe side. Here's an example of how you could validate a cuid(2) field using Zod:
import { z } from 'zod'

const cuid2Schema = z.string().max(30)
import { z } from 'zod'

const cuid2Schema = z.string().max(30)
It's important to note that while this validation should work for most cases, the exact length of cuid(2) IDs is not guaranteed to be fixed. If you need more precise validation, you might want to consider using a different ID generation method or consult the latest Prisma documentation for any updates on cuid(2) specifics. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Uncle
UncleOP•3d ago
is there a minimum size generated by prisma?
Nurul
Nurul•3d ago
https://www.prisma.io/docs/orm/reference/prisma-schema-reference#cuid Based on our docs, we recommend a safe size of 30 characters
Prisma Schema API | Prisma Documentation
API reference documentation for the Prisma Schema Language (PSL).
Uncle
UncleOP•3d ago
I understand that 30 is a good maximum but is there a good minimum?
Nurul
Nurul•2d ago
Usually I have observed that a minimum of 24 and a maximum of 30 is a safe rule
Uncle
UncleOP•2d ago
Thanks

Did you find this page helpful?