Skip to content

Support transactions #119

@maciejmyslinski

Description

@maciejmyslinski

Hey!

Thank you for creating this outstanding library, it really helps with testing.

One use case that I stumbled upon was the need to check if an object X exists in a database before I can create another object Y that has a relationship many to one with object X.

For example:

factory({
  reviewer: {
    id: primaryKey(Number),
    reporters: manyOf('reporter'),
  },
  reporter: {
    id: primaryKey(Number),
  }
})

Let's say I want to create a reporter for a given reviewer. First, I have to check if a reviewer exists, then I can create a reporter, then I can assign a reporter to a reviewer. Otherwise, if the reviewer would not exist, the code would fail on the last step and the reviewer would hang in the database unnecessarily.

In contract, with transacions, if it fails at any step, all operations would be rolled back.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions