@entity-factory/typeorm
Advanced tools
TypeORM Adapter for entity-factory
Weekly downloads
Readme
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.
The TypeormAdapter is used for creating mock data and automatically inserting persisting it to a database.
npm install --save factory/core -factory/typeorm
-import { EntityFactory } from '@entity-factory/core';
import { TypeormAdapter } from '@entity-factory/typeorm';
import { Widget } from './entities/widget';
// use default connection from ormconfig.json
const typeormAdapter = new TypeormAdapter();
// or use any valid typeorm connection options
const typeormAdapter = new TypeormAdapter({
type: 'sqlite',
database: ':memory:',
synchronize: true,
entities: [Widget],
});
const factory = new EntityFactory({
adapter: typeormAdapter,
});
opts
is omitted then the adapter will attempt to use the connection configured in
ormconfig.json
Available Options None
import { TypeormBlueprint } from ' -factory/typeorm';
import { Widget } from './entities/widget';
export class WidgetBlueprint extends TypeormBlueprint<Widget> {
constructor() {
super();
this.type(Widget);
this.define(async ({ faker, factory }) => {
/* ... */
});
}
}