docker compose exec node npx nest generate service posts
import{Injectable}from"@nestjs/common";import{InjectRepository}from"@nestjs/typeorm";import{Repository}from"typeorm";import{Post}from"./posts.entity";@Injectable()exportclassPostsService{publicconstructor(@InjectRepository(Post)privatereadonlypostRepository:Repository<Post>){}publicasyncseed(){constpost1=this.postRepository.create({title:"How to use TypeORM with NestJS",body:"This is a test post."});constpost2=this.postRepository.create({title:"How to use React with NestJS",body:"This is another test post."});awaitthis.postRepository.delete({});awaitthis.postRepository.save([post1,post2]);}}
Did you consider using typeorm factory package along with faker for the actual data seeding?
We are using it to populate integration tests (with sqlite), it drastically eased setting up related data and faking emails, content, addresses and such.
I don't use Factories too much because I was in search of an official solution from TypeORM but as far as I can tell there are only few libraries that will do such work.
I'm waiting for a library that will have a great developer experience to setup MTM relationships between factories without the hassle and setting up data that are related easily.
Have you found any interesting ones?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (2)
Did you consider using typeorm factory package along with faker for the actual data seeding?
We are using it to populate integration tests (with sqlite), it drastically eased setting up related data and faking emails, content, addresses and such.
Hi Pierre and thanks for your comment!
I don't use Factories too much because I was in search of an official solution from TypeORM but as far as I can tell there are only few libraries that will do such work.
I'm waiting for a library that will have a great developer experience to setup MTM relationships between factories without the hassle and setting up data that are related easily.
Have you found any interesting ones?