Files
FastGPT/packages/service/common/mongo/sessionRun.ts
Archer a259d034b8 4.8.3 (#1654)
* Milvus (#1644)

* feat: support regx

* 4.8.3 test and fix (#1648)

* perf: version tip

* feat: sandbox support log

* fix: debug component render

* fix: share page header

* fix: input guide auth

* fix: iso viewport

* remove file

* fix: route url

* feat: add debug timout

* perf: reference select support trigger

* perf: session code

* perf: theme

* perf: load milvus
2024-06-01 09:26:11 +08:00

20 lines
504 B
TypeScript

import { connectionMongo, ClientSession } from './index';
export const mongoSessionRun = async <T = unknown>(fn: (session: ClientSession) => Promise<T>) => {
const session = await connectionMongo.startSession();
try {
session.startTransaction();
const result = await fn(session);
await session.commitTransaction();
return result as T;
} catch (error) {
await session.abortTransaction();
return Promise.reject(error);
} finally {
await session.endSession();
}
};