Skip to content

Commit 486ca8d

Browse files
authored
Merge pull request #64 from Findeton/master
Add optional isolation level configuration to sql transactions
2 parents 636a31b + a5db8b3 commit 486ca8d

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-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_UNCOMMITTED = "READ_UNCOMMITTED",
9+
}

src/datastore/drivers/pg/PGStore.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PGIsolationLevel } from "../../abstract/PGIsolationLevel"
12
import { PGTransaction } from "./PGTransaction"
23
import { SQLStore } from "../../abstract/SQLStore"
34
import { Container } from "inversify"
@@ -34,15 +35,36 @@ export class PGStore implements Process, SQLStore {
3435
}
3536
}
3637

37-
public async createTransaction(): Promise<PGTransaction> {
38+
public async createTransaction(
39+
isolationLevel?: PGIsolationLevel
40+
): Promise<PGTransaction> {
3841
if (this.connection === undefined) {
3942
throw new Error(
4043
"PGStore cannot open a transaction on a closed Pool. This usually happens from forgetting to call startup."
4144
)
4245
}
4346

4447
let connection = await this.connection.connect()
45-
await connection.query("BEGIN")
48+
49+
// By default, use PostgreSQL default isolation level (READ COMMITTED)
50+
let query = "BEGIN"
51+
if (isolationLevel !== undefined) {
52+
switch (isolationLevel) {
53+
case PGIsolationLevel.SERIALIZABLE:
54+
query = "BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE"
55+
break
56+
case PGIsolationLevel.REPEATABLE_READ:
57+
query = "BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ"
58+
break
59+
case PGIsolationLevel.READ_COMMITED:
60+
query = "BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED"
61+
break
62+
case PGIsolationLevel.READ_UNCOMMITTED:
63+
query = "BEGIN TRANSACTION ISOLATION LEVEL READ UNCOMMITTED"
64+
break
65+
}
66+
}
67+
await connection.query(query)
4668

4769
return new PGTransaction(connection, this.logger)
4870
}

src/datastore/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./abstract/SQLStore"
2+
export * from "./abstract/PGIsolationLevel"
23

34
export * from "./drivers/mysql/MySQLStore"
45
export * from "./drivers/mysql/MySQLTransaction"

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 standardize levels used across all Logger integrations
33
*/
44
export enum LogLevel {
55
/**

0 commit comments

Comments
 (0)