Skip to content

Commit

Permalink
Transaction should return
Browse files Browse the repository at this point in the history
  • Loading branch information
nad-au committed May 15, 2023
1 parent d648da0 commit 1b83051
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dbc-tech/nest-neo4j",
"version": "0.6.0",
"version": "0.7.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.js",
Expand Down
9 changes: 5 additions & 4 deletions src/neo4j.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ export class Neo4jService implements OnApplicationShutdown {
return res
}

transaction = async (
run?: (_: Transaction) => Promise<void>,
async transaction<Result>(
run?: (_: Transaction) => Promise<Result>,
onCommitError?: (error: Error) => Promise<void>,
) => {
): Promise<Result> {
const session = this.getWriteSession()
const tx = await session.beginTransaction()
try {
await run(tx)
const result = await run(tx)
try {
await tx.commit()
return result
} catch (error) {
if (onCommitError) await onCommitError(error)
throw error // roll back
Expand Down

0 comments on commit 1b83051

Please sign in to comment.