edwardanthony / nestjs-seeder

An extension library for NestJS to perform seeding.
MIT License
102 stars 21 forks source link

Is there any way of setting sequential numbers? #13

Open tomcastro opened 3 years ago

tomcastro commented 3 years ago

I have a specific use case where I need static ids, but random data. Is there a way to run DataFactory.generate, but to pass the current iteration number to the context?

For example

// school.seeder.ts
public async seed() {
  const schools = DataFactory.createForClass(School).generate(10)
}
// school.entity.ts
@Factory((_, ctx) => ctx.idx) // GET CURRENT ITERATION FOR THIS CONTEXT
@PrimaryGeneratedColumn()
schoolId: number

I guess I could just replace them before saving them, but I was hoping there was a way of injecting this data into the current iteration context.

Or is there maybe another way I'm not contemplating? Would this be helpful as a PR?

Let me know what you think!

simplenotezy commented 2 years ago

@tomcastro Could this help? https://github.com/edwardanthony/nestjs-seeder#userschemats-1