@entity-factory/typeorm
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

Entity Factory Typeorm Adapter

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.

Documentation

Features

  • Generate plain javascript objects on demand
  • Generate objects with nested relations
  • Typeorm Support - Generate Entities and Persist Entities and nested relations

TypeORM Adapter

Installation

npm install --save @entity-factory/core @entity-factory/typeorm

TypeormAdapter

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: optional, any valid Typeorm Connection Options. If opts is omitted then the adapter will attempt to use the connection configured in ormconfig.json

Typeorm Blueprint

Available Options None

import { TypeormBlueprint } from '@entity-factory/typeorm';
import { Widget } from './entities/widget';

export class WidgetBlueprint extends TypeormBlueprint<Widget> {
    constructor() {
        super();

        this.type(Widget);

        this.define(async ({ faker, factory }) => {
            /* ... */
        });
    }
}

Package Sidebar

Install

npm i @entity-factory/typeorm

Weekly Downloads

8

Version

0.2.2

License

MIT

Unpacked Size

15 kB

Total Files

13

Last publish

Collaborators

  • jcloutz