prisma-generator-fake-data icon indicating copy to clipboard operation
prisma-generator-fake-data copied to clipboard

How to override what faker.js generates for a specific fields

Open laneme opened this issue 2 years ago • 7 comments

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.

laneme avatar Jul 25 '23 19:07 laneme

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.

luisrudge avatar Jul 25 '23 20:07 luisrudge

follow up here: https://github.com/prisma/prisma/issues/20385

luisrudge avatar Jul 25 '23 20:07 luisrudge

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

laneme avatar Jul 25 '23 20:07 laneme

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.

mjjjjjjlindow avatar Nov 28 '23 17:11 mjjjjjjlindow

I'd be happy to review and merge a PR with this change!

luisrudge avatar Nov 28 '23 17:11 luisrudge

Sounds good! I will see if I can work that in.

mjjjjjjlindow avatar Nov 29 '23 00:11 mjjjjjjlindow

+1 need this as well.

jamespsterling avatar Dec 04 '23 20:12 jamespsterling