Skip to content

Commit

Permalink
Export close function to close db
Browse files Browse the repository at this point in the history
  • Loading branch information
romeerez committed Apr 9, 2024
1 parent 6738c12 commit 280f2f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
patchPgForTransactions,
startTransaction,
rollbackTransaction,
close,
} from 'pg-transactional-tests';

// import instance of your query builder, ORM, something which has `.close` or `.end` or `.destroy` method
Expand All @@ -68,7 +69,7 @@ afterAll(async () => {
// rollback transaction after all tests:
await rollbackTransaction()
// end database connection:
await db.close()
await close()
});
```

Expand All @@ -81,11 +82,9 @@ import {
patchPgForTransactions,
startTransaction,
rollbackTransaction,
close,
} from 'pg-transactional-tests';

// import instance of your query builder, ORM, something which has `.close` or `.end` or `.destroy` method
import db from './path-to-your-db'

export const useTestDatabase = () => {
beforeAll(async () => {
patchPgForTransactions()
Expand All @@ -96,7 +95,7 @@ export const useTestDatabase = () => {
afterAll(async () => {
await rollbackTransaction()
unpatchPgForTransactions()
await db.close()
await close()
})
}
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-transactional-tests",
"version": "1.0.8",
"version": "1.0.9",
"description": "Wraps each test in transaction for `pg` package",
"repository": "https://github.com/romeerez/pg-transactional-tests",
"main": "dist/index.js",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ export const rollbackTransaction = async () => {
await client?.query('ROLLBACK');
}
};

export const close = () => client?.end();

0 comments on commit 280f2f6

Please sign in to comment.