@stashfin/mysql2 1.3.5 → 1.3.7

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,17 @@
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
+ }
@@ -0,0 +1,73 @@
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;
@@ -0,0 +1,23 @@
1
+ import { RowDataPacket } from 'mysql2';
2
+ export type JSONPrimitive = string | number | boolean | null;
3
+ export type JSONValue = JSONObject | JSONArray;
4
+ export type JSONObject = {
5
+ [member: string]: JSONPrimitive;
6
+ };
7
+ export type JSONArray = Array<JSONValue>;
8
+ export interface BBPSProvidersTable {
9
+ id: number;
10
+ name: string;
11
+ logo: string;
12
+ state: string;
13
+ data: JSONValue;
14
+ utilityid: number;
15
+ vendorid: number;
16
+ billerid: string;
17
+ created_at: Date;
18
+ updated_at: Date;
19
+ is_active: number;
20
+ is_deleted: number;
21
+ }
22
+ export interface BBPSProvidersModel extends BBPSProvidersTable, RowDataPacket {
23
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
1
+ import { RowDataPacket } from 'mysql2';
2
+ export interface BBPSTransactionsTable {
3
+ id: number;
4
+ customerid: number;
5
+ utilityid: number;
6
+ providerid: number;
7
+ account: string;
8
+ billamount: number;
9
+ amount: number;
10
+ discount: number;
11
+ promo: string;
12
+ duedate: Date;
13
+ status: string;
14
+ mode: string;
15
+ paymentid: string;
16
+ txnid: string;
17
+ attempted_at: Date;
18
+ paid_at: Date;
19
+ processed_at: Date;
20
+ created_at: Date;
21
+ updated_at: Date;
22
+ is_active: number;
23
+ is_deleted: number;
24
+ }
25
+ export interface BBPSTransactionsModel extends BBPSTransactionsTable, RowDataPacket {
26
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import { RowDataPacket } from 'mysql2';
2
+ export interface BBPSUtilitiesTable {
3
+ id: number;
4
+ name: string;
5
+ logo: string;
6
+ vendorid: number;
7
+ created_at: Date;
8
+ updated_at: Date;
9
+ is_active: number;
10
+ is_deleted: number;
11
+ }
12
+ export interface BBPSUtilitiesModel extends BBPSUtilitiesTable, RowDataPacket {
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import { RowDataPacket } from 'mysql2';
2
+ export interface BBPSVendorsTable {
3
+ id: number;
4
+ name: string;
5
+ created_at: Date;
6
+ updated_at: Date;
7
+ is_active: number;
8
+ is_deleted: number;
9
+ }
10
+ export interface BBPSVendorsModel extends BBPSVendorsTable, RowDataPacket {
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -41,6 +41,12 @@ export interface CustomerTable {
41
41
  tnc_version?: string | null;
42
42
  login_date?: Date | null;
43
43
  agent_id?: number | null;
44
+ /** Defaults to: new */
45
+ application_type?: string | null;
46
+ /** Defaults to: incomplete */
47
+ application_status?: string | null;
48
+ /** Defaults to: organic */
49
+ customer_type?: string | null;
44
50
  /** Defaults to: CURRENT_TIMESTAMP. */
45
51
  created_at?: Date | null;
46
52
  /** Defaults to: CURRENT_TIMESTAMP. */
@@ -0,0 +1,36 @@
1
+ import { RowDataPacket } from 'mysql2';
2
+ export type JSONPrimitive = string | number | boolean | null;
3
+ export type JSONValue = JSONObject | JSONArray;
4
+ export type JSONObject = {
5
+ [member: string]: JSONPrimitive;
6
+ };
7
+ export type JSONArray = Array<JSONValue>;
8
+ export interface InstallmentsTable {
9
+ id?: number | null;
10
+ customer_id: number | null;
11
+ loan_id?: number | null;
12
+ seq_no: number | null;
13
+ amount?: number | null;
14
+ principal?: number | null;
15
+ interest?: number | null;
16
+ penalty?: number | null;
17
+ r_principal?: number | null;
18
+ r_interest?: number | null;
19
+ r_penalty?: number | null;
20
+ r_pif_principal?: number | null;
21
+ r_pif_interest?: number | null;
22
+ r_pif_penalty?: number | null;
23
+ status?: 'active' | 'closed' | 'delayed' | 'paid' | 'future' | null;
24
+ dpd?: number | null;
25
+ due_date?: Date | null;
26
+ discount?: number | null;
27
+ starting_balance?: number | null;
28
+ ending_balance?: number | null;
29
+ closed_at?: Date | null;
30
+ created_at?: Date | null;
31
+ updated_at?: Date | null;
32
+ is_active?: number | null;
33
+ is_deleted?: number | null;
34
+ }
35
+ export interface InstallmentsModel extends InstallmentsTable, RowDataPacket {
36
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stashfin/mysql2",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",