Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add em.begin/commit/rollback methods #717

Merged
merged 1 commit into from Aug 8, 2020
Merged

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Aug 8, 2020

This brings back the explicit begin/commit/rollback way of handling
transactions (similar to what we had in v2).

const em = orm.em.fork(false);
await em.begin();

try {
  //... do some work
  const user = new User(...);
  user.name = 'George';
  em.persist(user);
  await em.commit(); // will flush before making the actual commit query
} catch (e) {
  await em.rollback();
  throw e;
}

This brings back the explicit `begin/commit/rollback` way of handling
transactions (similar to what we had in v2).

```typescript
const em = orm.em.fork(false);
await em.begin();

try {
  //... do some work
  const user = new User(...);
  user.name = 'George';
  em.persist(user);
  await em.commit(); // will flush before making the actual commit query
} catch (e) {
  await em.rollback();
  throw e;
}
```
@B4nan B4nan mentioned this pull request Aug 8, 2020
46 tasks
@B4nan B4nan merged commit 448f56a into dev Aug 8, 2020
@B4nan B4nan deleted the transactions branch August 8, 2020 11:09
B4nan added a commit that referenced this pull request Aug 9, 2020
This brings back the explicit `begin/commit/rollback` way of handling
transactions (similar to what we had in v2).

```typescript
const em = orm.em.fork(false);
await em.begin();

try {
  //... do some work
  const user = new User(...);
  user.name = 'George';
  em.persist(user);
  await em.commit(); // will flush before making the actual commit query
} catch (e) {
  await em.rollback();
  throw e;
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant