{"id":19186350,"url":"https://github.com/vantezzen/typeorm-seeding","last_synced_at":"2026-04-25T22:33:28.194Z","repository":{"id":64230386,"uuid":"573872027","full_name":"vantezzen/typeorm-seeding","owner":"vantezzen","description":"🌱 Laravel-inspired seeding system for TypeORM","archived":false,"fork":false,"pushed_at":"2022-12-03T17:46:15.000Z","size":78,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-16T18:19:51.636Z","etag":null,"topics":["database","typeorm","typeorm-seeding","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@vantezzen/typeorm-seeding","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vantezzen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-03T17:43:06.000Z","updated_at":"2022-12-03T17:48:19.000Z","dependencies_parsed_at":"2023-01-15T05:46:05.811Z","dependency_job_id":null,"html_url":"https://github.com/vantezzen/typeorm-seeding","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vantezzen/typeorm-seeding","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vantezzen%2Ftypeorm-seeding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vantezzen%2Ftypeorm-seeding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vantezzen%2Ftypeorm-seeding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vantezzen%2Ftypeorm-seeding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vantezzen","download_url":"https://codeload.github.com/vantezzen/typeorm-seeding/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vantezzen%2Ftypeorm-seeding/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32279655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T18:29:39.964Z","status":"ssl_error","status_checked_at":"2026-04-25T18:29:32.149Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","typeorm","typeorm-seeding","typescript"],"created_at":"2024-11-09T11:14:23.286Z","updated_at":"2026-04-25T22:33:28.161Z","avatar_url":"https://github.com/vantezzen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @vantezzen/typeorm-seeding\n\n\u003e Laravel-inspired seeding system for TypeORM\n\n[![NPM](https://img.shields.io/npm/v/@vantezzen/typeorm-seeding.svg)](https://www.npmjs.com/package/@vantezzen/typeorm-seeding) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nThis package adds a seeding and factory pattern to TypeORM entities. If you are familiar with Seeding in Laravel or similar frameworks, you'll feel right at home!\n\nThe library is intentionally minimal and only implements required boilerplate so you can quickly create seeding data. It doesn't provide a CLI or commands to seed, but rather allows you to run the seeders anywhere in your code.\n\n## Install\n\n```bash\nnpm install @vantezzen/typeorm-seeding typeorm\n```\n\nIt is highly recommended - though not required - to also install faker.js for generating fake data in your Factories:\n\n```bash\nnpm install @faker-js/faker\n```\n\n## Usage\n\nA complete example on how to use this library can be found in the \"example\" folder.\n\n### Factory\n\nA factory allows creating dummy instances of your entities.\n\nExample of a factory for a \"Purchase\" entity:\n\n```tsx\nimport { Factory } from \"@vantezzen/typeorm-seeding\";\n\n// Your entity that you want to seed\nimport Purchase from \"../entities/Purchase\";\n\n// Faker.js is recommended but not required\nimport { faker } from \"@faker-js/faker\";\n\nexport default class PurchaseFactory\n  // Your factory should extend this package's base factory\n  // The first generic is your entity. This is used to improve type support\n  extends Factory\u003cPurchase\u003e\n{\n  // Implement a \"getEntity\" function that simply returns the entity class that should be used\n  getEntity() {\n    return Purchase;\n  }\n\n  // Implement a \"getFactoryData\" function that returns the data needed to instanciate a new entity\n  getFactoryData() {\n    return {\n      shopName: faker.company.name(), // Faker is used here to get random data for each new entity\n      purchasedAt: faker.date.past(),\n    };\n  }\n}\n```\n\nTo create new entities using this factory, simply call the \"create()\" method provided by the base factory:\n\n```ts\nconst factory = new PurchaseFactory();\nconst purchases = await factory.create();\n```\n\nThe return value is an **array** of entities.\n\n#### Using options\n\nOptionally, your factory can also type hint that options can be provided:\n\n```tsx\nimport { Factory } from \"@vantezzen/typeorm-seeding\";\nimport Purchase from \"../entities/Purchase\";\nimport { faker } from \"@faker-js/faker\";\n\nexport type PurchaseFactoryOptions = {\n  purchaseDate?: Date;\n};\n\n// Provide the type of your options as the second generic\nexport default class PurchaseFactory extends Factory\u003c\n  Purchase,\n  PurchaseFactoryOptions\n\u003e {\n  getEntity() {\n    return Purchase;\n  }\n\n  // Please note that these options will be made optional - your factory should still work, even if \"undefined\" is supplied\n  getFactoryData(options?: PurchaseFactoryOptions) {\n    return {\n      shopName: faker.company.name(),\n      purchasedAt: options?.purchaseDate ?? faker.date.past(),\n    };\n  }\n}\n```\n\nThe option values can be provided using a parameter to \".create()\":\n\n```ts\nconst factory = new PurchaseFactory();\nconst purchases = await factory.create({\n  purchaseDate: new Date(),\n});\n```\n\n#### Override values\n\nWhen using a factory, you might want to force override specific values. These can simply call \"withOverrideData\":\n\n```ts\nconst factory = new PurchaseFactory();\nconst purchases = await factory\n  .withOverrideData({\n    shopName: \"Foo Bar\",\n  })\n  .create();\n// shop name will be \"Foo Bar\" for all entitites\n```\n\n#### Creating multiple entities at once\n\n\".create()\" will return an array of entities as the factory is designed to create multiple entities at once if needed.\n\nTo set the count of entities to create, you can:\n\n- Pass the number to the constructor (like in Laravel):\n\n```ts\nconst factory = new PurchaseFactory(10);\nconst purchases = await factory.create();\n// \"purchases\" contains 10 entities\n```\n\n- Set the count with \"withCount\":\n\n```ts\nconst factory = new PurchaseFactory();\nconst purchases = await factory.withCount(10).create();\n// \"purchases\" contains 10 entities\n```\n\n### Seeder\n\nSeeders allow calling and combining Factories. To create a seeder, simply extend the base seeder and implement a \"run\" method.\n\n```ts\nimport { Seeder } from \"@vantezzen/typeorm-seeding\";\n\n// Factories that you want to use in your seeder\nimport PurchaseFactory from \"../factories/PurchaseFactory\";\nimport PurchaseItemFactory from \"../factories/PurchaseItemFactory\";\n\nexport default class PurchaseSeeder extends Seeder {\n  async run() {\n    // Create 10 purchases\n    const purchaseFactory = new PurchaseFactory(10);\n    const purchases = await purchaseFactory.create();\n\n    // Create 10 purchaseItems for each created purchase\n    const purchaseItemFactory = new PurchaseItemFactory(10);\n    purchases.forEach((purchase) =\u003e {\n      purchaseItemFactory.create({ purchase });\n    });\n  }\n}\n```\n\nYou can simply call this \"run\" method to execute the seeder:\n\n```ts\nconst seeder = new PurchaseSeeder();\nawait seeder.run();\n```\n\n#### Running multiple seeders\n\nThe library provides a simple helper method that allows running your seeders easily:\n\n```ts\nimport PurchaseSeeder from \"./PurchaseSeeder\";\nimport SomeOtherSeeder from \"./SomeOtherSeeder\";\nimport { runSeeders } from \"@vantezzen/typeorm-seeding\";\n\nconst runAllSeeders = () =\u003e runSeeders([PurchaseSeeder, SomeOtherSeeder]);\n\nawait runAllSeeders();\n```\n\nYou may also use this function inside your seeders to call other seeders. Please note that your provided seeders will run pseudo-parallel using `Promise.all` so do not expect certain seeders to have completed before others.\n\n## Development\n\n1. Clone this repository\n2. Run `npm install` in the root directory and `/example` (`npm i \u0026\u0026 cd example \u0026\u0026 npm i`)\n3. Run `npm start` in `/example` to start development using the example project\n4. You can use `npm test` to run the Jest tests\n\n## License\n\nMIT © [vantezzen](https://github.com/vantezzen)\n\n---\n\nThis project is created using [create-react-hook](https://github.com/hermanya/create-react-hook).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvantezzen%2Ftypeorm-seeding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvantezzen%2Ftypeorm-seeding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvantezzen%2Ftypeorm-seeding/lists"}