@dascompany/database 4.0.8 → 4.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export default class TransactionClient {
|
|
2
|
+
client;
|
|
3
|
+
active = false;
|
|
4
|
+
constructor(client) {
|
|
5
|
+
this.client = client;
|
|
6
|
+
}
|
|
7
|
+
async beginTransaction() {
|
|
8
|
+
if (this.active) {
|
|
9
|
+
throw new Error('Transaction already active');
|
|
10
|
+
}
|
|
11
|
+
await this.client.query('BEGIN');
|
|
12
|
+
this.active = true;
|
|
13
|
+
}
|
|
14
|
+
async commitTransaction() {
|
|
15
|
+
if (!this.active) {
|
|
16
|
+
throw new Error('No active transaction to commit');
|
|
17
|
+
}
|
|
18
|
+
await this.client.query('COMMIT');
|
|
19
|
+
this.client.release();
|
|
20
|
+
this.active = false;
|
|
21
|
+
}
|
|
22
|
+
async rollBackTransaction() {
|
|
23
|
+
if (!this.active) {
|
|
24
|
+
throw new Error('No active transaction to roll back');
|
|
25
|
+
}
|
|
26
|
+
await this.client.query('ROLLBACK');
|
|
27
|
+
this.client.release();
|
|
28
|
+
this.active = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default class ResultsCorrector {
|
|
2
|
+
static correctRows(rows) {
|
|
3
|
+
rows.forEach((row) => {
|
|
4
|
+
Object.keys(row).forEach((key) => {
|
|
5
|
+
if (this.isNumber(row[key]))
|
|
6
|
+
row[key] = Number(row[key]);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
return rows;
|
|
10
|
+
}
|
|
11
|
+
static isNumber(n) {
|
|
12
|
+
return !isNaN(parseFloat(n)) && !isNaN(n - 0);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -2,8 +2,8 @@ import StockObjectMapper from "./StockObjectMapper";
|
|
|
2
2
|
export default abstract class StockObject {
|
|
3
3
|
private id;
|
|
4
4
|
protected abstract getMapper(): StockObjectMapper;
|
|
5
|
-
getId():
|
|
6
|
-
setId(
|
|
5
|
+
getId(): string | null;
|
|
6
|
+
setId(id: string): void;
|
|
7
7
|
save(): Promise<void>;
|
|
8
8
|
delete(): Promise<void>;
|
|
9
9
|
}
|