1.1.0 • Published 8 years ago

fabrica v1.1.0

Weekly downloads
37
License
MIT
Repository
github
Last release
8 years ago

Fabrica

TBD

Example

const { define, create, build } = require("fabrica")();

define("book")
  .attr("title", "Hai")

  // "Lazy" attributes
  .attr("date", () => Date.now())

  // "Sequence" attributes
  .sequence("isbn", sequenceNumber => `${sequenceNumber}`)

  // Relations
  .attr("author", () => create("user"))

  // Custom build method
  .build(attributes => new Post(attributes))

  // Custom create method
  .create(attributes => postRepository.create(attributes))

  // Traits
  .trait("withoutTitle", trait => {
    trait.attr("title", null);
  });

build("book", "withoutTitle")
  .then(book => console.log(book.title || "Untitled", "by", author.name));

create("book")
  .then(book => console.log("Persisted book with id", book.id));
1.1.0

8 years ago

1.0.0

8 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago