prisma-generator-fake-data
prisma-generator-fake-data copied to clipboard
How to override what faker.js generates for a specific fields
Trying to achieve this
/// FAKE: faker.database.mongodbObjectId()
user_id String @db.ObjectId
It still generates a fake string user_id: faker.lorem.words(5)
I know its already possible to generate cusom JSONs and that works! But this wouldve been a nice addition.
I'm not sure if it already exist.
Yeah, that's a good idea. I tried to find a way to get the @db.ObjectId info from the model info, but it's not exposed anywhere. Ideally, we'd just detect that and use mongodbObjectId instead. I'll ping someone from the Prisma team to see if it's possible.
follow up here: https://github.com/prisma/prisma/issues/20385
That would definitely be the most ideal way of doing it. But i would still be open to the idea of overriding with comments.
I know faker text generation is supposted to save time but some time we might want someth more than just faker.lorem.words(5)
I used some zod schema generators and I have to override them for almost most fields.
/// @zod.custom.use(z.coerce.number().positive({message: "Must be a positive interger"}))
Thanks for the lib btw <3
I second the idea of being able to override specific fields with:
/// FAKE: faker.someMethod()
or
/// Fake: someFunction()
This would be especially helpful for optional fields.
I'd be happy to review and merge a PR with this change!
Sounds good! I will see if I can work that in.
+1 need this as well.