Skip to content

Commit

Permalink
Allow using keyword with pool clients (#473)
Browse files Browse the repository at this point in the history
* feat: Allow `using` keyword with pool clients

* chore: fix deno lint error
  • Loading branch information
langpavel committed Feb 28, 2024
1 parent 5915574 commit 5e9075a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,8 @@ export class PoolClient extends QueryClient {
// Cleanup all session related metadata
this.resetSessionMetadata();
}

[Symbol.dispose]() {
this.release();
}
}
2 changes: 1 addition & 1 deletion query/array_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function parseArray<T>(
source: string,
transform: Transformer<T>,
separator: AllowedSeparators = ",",
) {
): ArrayResult<T> {
return new ArrayParser(source, transform, separator).parse();
}

Expand Down
12 changes: 12 additions & 0 deletions tests/pool_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,15 @@ Deno.test(
);
}),
);

Deno.test(
"Pool client will be released after `using` block",
testPool(async (POOL) => {
const initialPoolAvailable = POOL.available;
{
using _client = await POOL.connect();
assertEquals(POOL.available, initialPoolAvailable - 1);
}
assertEquals(POOL.available, initialPoolAvailable);
}),
);

1 comment on commit 5e9075a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No typecheck tests failure

This error was most likely caused by incorrect type stripping from the SWC crate

Please report the following failure to https://github.com/denoland/deno with a reproduction of the current commit

Failure log

Please sign in to comment.