@stashfin/mysql2 1.3.3 → 1.3.5

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.
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import mysql, { RowDataPacket, PoolOptions, ResultSetHeader } from 'mysql2';
2
- import { Connection } from 'mysql2/typings/mysql/lib/Connection';
3
2
  export interface MysqlConnectorOptions extends PoolOptions {
4
3
  }
5
4
  export declare class MysqlConnector {
@@ -8,7 +7,7 @@ export declare class MysqlConnector {
8
7
  constructor(credentials: PoolOptions);
9
8
  /** A random method to simulate a step before to get the class methods */
10
9
  getPoolConnection(): mysql.Pool;
11
- getConnection(): Promise<Connection>;
10
+ getConnection(): Promise<import("mysql2/promise").PoolConnection>;
12
11
  queryRow<T extends RowDataPacket>(sql: string, values?: Array<string | number>): Promise<T | undefined>;
13
12
  queryRows<T extends RowDataPacket>(sql: string, values?: Array<string | number>): Promise<T[]>;
14
13
  queryArray<T extends RowDataPacket>(sql: string, values?: Array<string | number>): Promise<T[]>;
package/index.js CHANGED
@@ -22,13 +22,7 @@ class MysqlConnector {
22
22
  getConnection() {
23
23
  if (!this?.pool)
24
24
  this.pool = mysql2_1.default.createPool(this.credentials);
25
- return new Promise((resolve, reject) => {
26
- this.pool.getConnection((err, connection) => {
27
- if (err)
28
- reject(err);
29
- resolve(connection);
30
- });
31
- });
25
+ return this.pool.promise().getConnection();
32
26
  }
33
27
  async queryRow(sql, values) {
34
28
  const pool = this.getPoolConnection();
@@ -23,8 +23,9 @@ export interface StashCashTrascationTable {
23
23
  locked: number;
24
24
  unlocked: number;
25
25
  remaining: number;
26
- txn_type: 'debit' | 'credit' | 'expired' | 'reversal';
27
- status?: 'pending' | 'success' | 'failure' | 'reversed';
26
+ txn_type: 'debit' | 'credit';
27
+ sub_type: 'rewarded' | 'paid' | 'expired' | 'reversed' | 'transferred';
28
+ status?: 'pending' | 'success' | 'failure';
28
29
  expiry?: Date | null;
29
30
  is_expired: boolean;
30
31
  /** Defaults to: CURRENT_TIMESTAMP. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stashfin/mysql2",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/index copy.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import mysql, { RowDataPacket, PoolOptions, ResultSetHeader } from 'mysql2/promise';
2
- export interface MysqlConnectorOptions extends PoolOptions {
3
- }
4
- export declare class MysqlConnector {
5
- private pool;
6
- private credentials;
7
- constructor(credentials: PoolOptions);
8
- /** A random method to simulate a step before to get the class methods */
9
- getConnection(): Promise<mysql.PoolConnection>;
10
- queryRow<T extends RowDataPacket>(sql: string, values?: Array<string | number>): Promise<T | undefined>;
11
- queryRows<T extends RowDataPacket>(sql: string, values?: Array<string | number>): Promise<T[]>;
12
- queryArray<T extends RowDataPacket>(sql: string, values?: Array<string | number>): Promise<T[]>;
13
- executeResult(sql: string, values?: unknown[]): Promise<ResultSetHeader>;
14
- insertData(tableName: string, data: Record<string, string | number>): Promise<ResultSetHeader>;
15
- updateData(tableName: string, data: Record<string, any>, condition: string, conditionValues?: Array<string | number>): Promise<ResultSetHeader>;
16
- close(): Promise<void>;
17
- }
package/index copy.js DELETED
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MysqlConnector = void 0;
7
- const promise_1 = __importDefault(require("mysql2/promise"));
8
- //define class
9
- class MysqlConnector {
10
- pool;
11
- credentials;
12
- constructor(credentials) {
13
- this.credentials = credentials;
14
- this.pool = promise_1.default.createPool(this.credentials);
15
- }
16
- /** A random method to simulate a step before to get the class methods */
17
- getConnection() {
18
- if (!this?.pool)
19
- this.pool = promise_1.default.createPool(this.credentials);
20
- return this.pool.getConnection();
21
- }
22
- async queryRow(sql, values) {
23
- const connection = await this.getConnection();
24
- const [rows] = await connection.query(sql, values);
25
- await connection.release();
26
- return rows[0] || undefined;
27
- }
28
- async queryRows(sql, values) {
29
- const connection = await this.getConnection();
30
- const [rows] = await connection.query(sql, values);
31
- await connection.release();
32
- return rows;
33
- }
34
- async queryArray(sql, values) {
35
- const connection = await this.getConnection();
36
- const [rows] = await connection.query({
37
- sql,
38
- values,
39
- rowsAsArray: true,
40
- });
41
- await connection.release();
42
- return rows;
43
- }
44
- async executeResult(sql, values) {
45
- const connection = await this.pool.getConnection();
46
- const [rows] = await connection.query(sql, values);
47
- await connection.release();
48
- return rows;
49
- }
50
- async insertData(tableName, data) {
51
- const keys = Object.keys(data);
52
- const values = Object.values(data);
53
- const sql = `INSERT INTO ${tableName} (${keys.join(', ')}) VALUES (${keys
54
- .map(() => '?')
55
- .join(', ')})`;
56
- return this.executeResult(sql, values);
57
- }
58
- async updateData(tableName,
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- data, condition, conditionValues) {
61
- const keys = Object.keys(data);
62
- const values = Object.values(data);
63
- const sql = `UPDATE ${tableName} SET ${keys
64
- .map((key) => `${key} = ?`)
65
- .join(', ')} WHERE ${condition}`;
66
- const finalValues = [...values, ...(conditionValues || [])];
67
- return this.executeResult(sql, finalValues);
68
- }
69
- async close() {
70
- await this.pool.end();
71
- }
72
- }
73
- exports.MysqlConnector = MysqlConnector;