Skip to content

Commit

Permalink
Issue 442
Browse files Browse the repository at this point in the history
  • Loading branch information
groksrc committed Feb 2, 2024
1 parent 63d3d22 commit d0c20ec
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

0 comments on commit d0c20ec

Please sign in to comment.