Skip to content

Commit f4d42e2

Browse files
author
Felix Robles
committed
add optional isolation level config to transactions
1 parent 880a58a commit f4d42e2

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

src/cryptography/abstract/HMAC.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Digest } from "./Digest"
22
/**
3-
* A HMAC ( commonly referred to as a Hash ) (hash-based message authentication
3+
* A HMAC (hash-based message authentication
44
* code) is a type of message authentication code (MAC) that uses a
55
* cryptographic hash function and a secret key. It may be used to verify data
66
* integrity and authentication of a message.

src/cryptography/drivers/node/SHA1HMAC.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HMAC } from "../../abstract/HMAC"
22
import { createHmac } from "crypto"
33

44
/**
5-
* The SHA1HMAC provides a HMAC implementation using SHA1 based on Node's
5+
* The SHA1HMAC class provides a HMAC implementation using SHA1 based on Node's
66
* OpenSSL.
77
*
88
* This implementation relies on the node crypto implementation and may vary based
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* PostgreSQL transaction isolation levels
3+
*/
4+
export enum PGIsolationLevel {
5+
SERIALIZABLE = "SERIALIZABLE",
6+
REPEATABLE_READ = "REPEATABLE_READ",
7+
READ_COMMITED = "READ_COMMITED",
8+
READ_UNCOMMITED = "READ_UNCOMMITED",
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { PGIsolationLevel } from "./PGIsolationLevel"
2+
3+
/**
4+
* Set characteristics of the PostgreSQL transaction
5+
*/
6+
export interface PGTransactionOptions {
7+
isolation_level: PGIsolationLevel
8+
}

src/datastore/drivers/pg/PGStore.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { PGIsolationLevel } from "../../abstract/PGIsolationLevel"
12
import { PGTransaction } from "./PGTransaction"
3+
import { PGTransactionOptions } from "../../abstract/PGTransactionOptions"
24
import { SQLStore } from "../../abstract/SQLStore"
35
import { Container } from "inversify"
46
import { Logger } from "../../../logging"
@@ -34,15 +36,30 @@ export class PGStore implements Process, SQLStore {
3436
}
3537
}
3638

37-
public async createTransaction(): Promise<PGTransaction> {
39+
public async createTransaction(
40+
options?: Partial<PGTransactionOptions>
41+
): Promise<PGTransaction> {
3842
if (this.connection === undefined) {
3943
throw new Error(
4044
"PGStore cannot open a transaction on a closed Pool. This usually happens from forgetting to call startup."
4145
)
4246
}
4347

4448
let connection = await this.connection.connect()
45-
await connection.query("BEGIN")
49+
let query = "BEGIN"
50+
if (options !== undefined && options.isolation_level !== undefined) {
51+
switch (options.isolation_level) {
52+
case PGIsolationLevel.SERIALIZABLE:
53+
query = "BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE"
54+
case PGIsolationLevel.REPEATABLE_READ:
55+
query = "BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE_READ"
56+
case PGIsolationLevel.READ_COMMITED:
57+
query = "BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED"
58+
case PGIsolationLevel.READ_UNCOMMITED:
59+
query = "BEGIN TRANSACTION ISOLATION LEVEL READ UNCOMMITED"
60+
}
61+
}
62+
await connection.query(query)
4663

4764
return new PGTransaction(connection, this.logger)
4865
}

src/logging/abstract/LogLevel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* The standarzied levels used across all Logger integrations
2+
* The standarized levels used across all Logger integrations
33
*/
44
export enum LogLevel {
55
/**

0 commit comments

Comments
 (0)