Skip to content

Commit

Permalink
Issue 442 (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
groksrc authored Feb 2, 2024
1 parent 63d3d22 commit 427b77d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export abstract class QueryClient {
* https://www.postgresql.org/docs/14/sql-set-transaction.html
*/
createTransaction(name: string, options?: TransactionOptions): Transaction {
if (!name) {
throw new Error("Transaction name must be a non-empty string");
}

this.#assertOpenConnection();

return new Transaction(
Expand Down
13 changes: 13 additions & 0 deletions tests/query_client_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
assertEquals,
assertObjectMatch,
assertRejects,
assertThrows,
} from "./test_deps.ts";
import { getMainConfiguration } from "./config.ts";
import { PoolClient, QueryClient } from "../client.ts";
Expand Down Expand Up @@ -855,6 +856,18 @@ Deno.test(
}),
);

Deno.test(
"Transaction parameter validation",
withClient((client) => {
assertThrows(
// deno-lint-ignore ban-ts-comment
// @ts-expect-error
() => client.createTransaction(),
"Transaction name must be a non-empty string",
);
}),
);

Deno.test(
"Transaction",
withClient(async (client) => {
Expand Down

1 comment on commit 427b77d

@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.