0.0.14 • Published 4 years ago

typeorm-factory v0.0.14

Weekly downloads
2,175
License
MIT
Repository
github
Last release
4 years ago

typeorm-factory

CircleCI Coverage Status

typeorm-factory is a factory library for typeorm. It supports all databases that uses typeorm's Repository, so it doesn't support MongoDB, a pull request is welcome.

Installation

Node.js:

npm install --save-dev typeorm-factory
# or
yarn add --dev typeorm-factory

Usage

# be sure a typeorm connection is opened before create a factory
import { Factory } from "../../src/Factory";

const CommentFactory = new Factory(Comment)
  .sequence("text", (i) => `text ${i}`)
  .attr("authorName", "John Doe");

const AuthorFactory = new Factory(Author)
  .sequence("firstName", (i) => `John ${i}`)
  .sequence("lastName", (i) => `Doe ${i}`);

const PostFactory = new Factory(Post)
  .sequence("title", (i) => `title ${i}`)
  .sequence("text", (i) => `text ${i}`)
  .attr("likesCount", 10)
  .assocMany("comments", CommentFactory, 2)
  .assocOne("author", AuthorFactory);

const build = async () => {
  console.log(await PostFactory.build())
  console.log(await PostFactory.build({ text: 'Foo' }))
  console.log(await PostFactory.buildList(10))

  console.log(await PostFactory.create({ author: AuthorFactory.create() }))
  console.log(await PostFactory.createList(1))
}

build()
0.0.14

4 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago