0.0.12 • Published 1 year ago

db-fixture-generator v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

db-fixture-generator

A database and framework-agnostic fixture generator for NodeJS

This project is not yet stable, do not use it in production.

TODO

  • Settle internal api + yaml format
  • Ability to call methods (sync/async)
  • Basic math operations in output
  • Ability to set seed for generation on faker

Features

  • Database agnostic -- Use any ORM you would like.
  • Solves your fixtures dependency tree, creating entities in order as needed.
  • Ability to generate thousands of models quickly
  • Support for Mustache Templates
  • Support for FakerJS values
  • 100% Test Coverage
  • Supports YAML fixtures
  • Supports CommonJS + ESM

Usage

Create a file such as seed.ts

import {FixtureGenerator} from "db-fixture-generator";

(async () => {

    const options = {};
    const fixtures = await FixtureGenerator.fromFiles('./fixtures/**.yaml', options);

    await fixtures.create(async (entityKey, entityType, entityData) => {
        // persist data here
    });
})();

Run it

ts-node seed.ts

Examples - TypeORM

import {FixtureGenerator} from "db-fixture-generator";

(async () => {

    await dataSource.initialize();
    
    const fixtures = await FixtureGenerator.fromFiles('./fixtures/**.yaml', {
        formatRelationship: (entityType, entityData) => {
            return {
                id: entityData.id
            }
        }
    });

    await fixtures.create(async (entityKey, entityType, entityData) => {
        const repository = dataSource.getRepository(entityType);
        const created = repository.create(entityData);
        await repository.save(created);

        console.log(`Created ${entityType}`);
    });
})();

Examples - Prisma

import {FixtureGenerator} from "db-fixture-generator";
import {PrismaClient} from "@prisma/client";

(async () => {

    const prisma = new PrismaClient();
    
    const fixtures = await FixtureGenerator.fromFiles('./fixtures/**.yaml', {
        formatRelationship: (entityType, entityData) => {
            return {
                connect: {
                    id: entityData.id
                }
            }
        }
    });

    await fixtures.create(async (entityKey, entityType, entityData) => {
        await prisma[entityType].create(entityData);
    });
})();

Alternatives

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

1.0.0

1 year ago