MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / transactional

Method transactional

packages/mongodb/src/MongoConnection.ts:388–410  ·  view source on GitHub ↗
(
    cb: (trx: Transaction<ClientSession>) => Promise<T>,
    options: {
      isolationLevel?: IsolationLevel;
      ctx?: Transaction<ClientSession>;
      eventBroadcaster?: TransactionEventBroadcaster;
    } & TransactionOptions = {},
  )

Source from the content-addressed store, hash-verified

386 }
387
388 override async transactional<T>(
389 cb: (trx: Transaction<ClientSession>) => Promise<T>,
390 options: {
391 isolationLevel?: IsolationLevel;
392 ctx?: Transaction<ClientSession>;
393 eventBroadcaster?: TransactionEventBroadcaster;
394 } & TransactionOptions = {},
395 ): Promise<T> {
396 await this.ensureConnection();
397 const session = await this.begin(options);
398
399 try {
400 const ret = await cb(session);
401 await this.commit(session, options.eventBroadcaster);
402
403 return ret;
404 } catch (error) {
405 await this.rollback(session, options.eventBroadcaster);
406 throw error;
407 } finally {
408 await session.endSession();
409 }
410 }
411
412 override async begin(
413 options: {

Callers 3

runMethod · 0.45
callRoutineMethod · 0.45
runMethod · 0.45

Calls 3

beginMethod · 0.95
commitMethod · 0.95
rollbackMethod · 0.95

Tested by

no test coverage detected