@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,9 @@
1
+ import pg from 'pg';
2
+ export default class TransactionClient {
3
+ private client;
4
+ private active;
5
+ constructor(client: pg.PoolClient);
6
+ beginTransaction(): Promise<void>;
7
+ commitTransaction(): Promise<void>;
8
+ rollBackTransaction(): Promise<void>;
9
+ }
@@ -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,4 @@
1
+ export default class ResultsCorrector {
2
+ static correctRows(rows: Array<any>): Array<any>;
3
+ private static isNumber;
4
+ }
@@ -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(): number | null;
6
- setId(clientId: number): void;
5
+ getId(): string | null;
6
+ setId(id: string): void;
7
7
  save(): Promise<void>;
8
8
  delete(): Promise<void>;
9
9
  }
@@ -3,8 +3,8 @@ export default class StockObject {
3
3
  getId() {
4
4
  return this.id;
5
5
  }
6
- setId(clientId) {
7
- this.id = clientId;
6
+ setId(id) {
7
+ this.id = id;
8
8
  }
9
9
  async save() {
10
10
  await this.getMapper().save();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/database",
3
- "version": "4.0.8",
3
+ "version": "4.0.9",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",