Entity Factory is a library used for quickly creating fixture data from plain objects or classes using faker. Inspired by laravel's factories for generating test data. Currently the library supports plain JS objects and Typeorm entities.
Features
Generate plain javascript objects on demand
Generate objects with nested relations
Typeorm Support - Generate and Persist Entities and nested relations
Installation
npm install --save @entity-factory/core
Example
Try it on
// index.js
const { EntityFactory } = require('@entity-factory/core');
const { UserBlueprint } = require('./UserBlueprint');
const { PostBlueprint } = require('./PostBlueprint');
const entityFactory = new EntityFactory({
// blueprints can be an array of glob patterns, blueprint classes and/or blueprint instances
blueprints: [UserBlueprint, PostBlueprint],
});
// Generate entities
entityFactory
.for('user') // get builder instance for 'user'
.state('with-posts') // generate users with posts
.create(3); // generate 3 users with incrementing id's