mirror of
https://github.com/docmost/docmost.git
synced 2025-11-10 09:32:06 +10:00
18 lines
420 B
TypeScript
18 lines
420 B
TypeScript
import { DataSource, EntityManager } from 'typeorm';
|
|
|
|
export async function transactionWrapper(
|
|
operation: (...args) => any,
|
|
datasource: DataSource,
|
|
entityManager: EntityManager,
|
|
) {
|
|
if (entityManager) {
|
|
return await operation(entityManager);
|
|
} else {
|
|
return await datasource.manager.transaction(
|
|
async (manager: EntityManager) => {
|
|
return await operation(manager);
|
|
},
|
|
);
|
|
}
|
|
}
|