@stashfin/mysql2 1.4.657 → 1.4.659
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 +7 -0
- package/index.js +77 -0
- package/package.json +1 -1
- package/models/EQXCustomerModels.d.ts +0 -24
- package/models/EQXCustomerModels.js +0 -2
- package/models/EqxDeviceBindings.d.ts +0 -22
- package/models/EqxDeviceBindings.js +0 -13
- package/models/RewardsOffer.d.ts +0 -33
- package/models/RewardsOffer.js +0 -2
- package/models/WealthWebhook.d.ts +0 -14
- package/models/WealthWebhook.js +0 -2
package/index.d.ts
CHANGED
|
@@ -15,4 +15,11 @@ export declare class MysqlConnector {
|
|
|
15
15
|
insertData(tableName: string, data: Record<string, string | number>): Promise<ResultSetHeader>;
|
|
16
16
|
updateData(tableName: string, data: Record<string, any>, condition: string, conditionValues?: Array<string | number>): Promise<ResultSetHeader>;
|
|
17
17
|
close(): Promise<void>;
|
|
18
|
+
beginTransaction(): Promise<import("mysql2/promise").PoolConnection>;
|
|
19
|
+
commitTransaction(connection: any): Promise<void>;
|
|
20
|
+
rollbackTransaction(connection: any): Promise<void>;
|
|
21
|
+
executeInTransaction<T>(callback: (connection: any) => Promise<T>): Promise<T>;
|
|
22
|
+
executeResultInTransaction(connection: any, sql: string, values?: unknown[]): Promise<ResultSetHeader>;
|
|
23
|
+
insertDataInTransaction(connection: any, tableName: string, data: Record<string, string | number>): Promise<ResultSetHeader>;
|
|
24
|
+
updateDataInTransaction(connection: any, tableName: string, data: Record<string, any>, condition: string, conditionValues?: Array<string | number>): Promise<ResultSetHeader>;
|
|
18
25
|
}
|
package/index.js
CHANGED
|
@@ -94,5 +94,82 @@ class MysqlConnector {
|
|
|
94
94
|
async close() {
|
|
95
95
|
await this.pool.end();
|
|
96
96
|
}
|
|
97
|
+
// Transaction methods
|
|
98
|
+
async beginTransaction() {
|
|
99
|
+
const connection = await this.getConnection();
|
|
100
|
+
await connection.beginTransaction();
|
|
101
|
+
return connection;
|
|
102
|
+
}
|
|
103
|
+
async commitTransaction(connection) {
|
|
104
|
+
try {
|
|
105
|
+
await connection.commit();
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
connection.release();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async rollbackTransaction(connection) {
|
|
112
|
+
try {
|
|
113
|
+
await connection.rollback();
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
connection.release();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async executeInTransaction(callback) {
|
|
120
|
+
const connection = await this.beginTransaction();
|
|
121
|
+
try {
|
|
122
|
+
const result = await callback(connection);
|
|
123
|
+
await this.commitTransaction(connection);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
await this.rollbackTransaction(connection);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async executeResultInTransaction(connection, sql, values) {
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
connection.query(sql, values, function (err, results, fields) {
|
|
134
|
+
if (err)
|
|
135
|
+
reject(err);
|
|
136
|
+
else
|
|
137
|
+
resolve(results || undefined);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async insertDataInTransaction(connection, tableName, data) {
|
|
142
|
+
const keys = Object.keys(data);
|
|
143
|
+
const values = Object.values(data);
|
|
144
|
+
const sql = `INSERT INTO ${tableName} (${keys.join(', ')}) VALUES (${keys
|
|
145
|
+
.map(() => '?')
|
|
146
|
+
.join(', ')})`;
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
connection.query(sql, values, function (err, results, fields) {
|
|
149
|
+
if (err)
|
|
150
|
+
reject(err);
|
|
151
|
+
else
|
|
152
|
+
resolve(results || undefined);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async updateDataInTransaction(connection, tableName,
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
158
|
+
data, condition, conditionValues) {
|
|
159
|
+
const keys = Object.keys(data);
|
|
160
|
+
const values = Object.values(data);
|
|
161
|
+
const sql = `UPDATE ${tableName} SET ${keys
|
|
162
|
+
.map((key) => `${key} = ?`)
|
|
163
|
+
.join(', ')} WHERE ${condition}`;
|
|
164
|
+
const finalValues = [...values, ...(conditionValues || [])];
|
|
165
|
+
return new Promise((resolve, reject) => {
|
|
166
|
+
connection.query(sql, finalValues, function (err, results, fields) {
|
|
167
|
+
if (err)
|
|
168
|
+
reject(err);
|
|
169
|
+
else
|
|
170
|
+
resolve(results || undefined);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
97
174
|
}
|
|
98
175
|
exports.MysqlConnector = MysqlConnector;
|
package/package.json
CHANGED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { RowDataPacket } from "mysql2";
|
|
2
|
-
interface EqxCustomersTable {
|
|
3
|
-
id: number;
|
|
4
|
-
mobile: string;
|
|
5
|
-
first_name?: string;
|
|
6
|
-
last_name?: string;
|
|
7
|
-
upi_number?: string;
|
|
8
|
-
upi_onboarding_status?: boolean;
|
|
9
|
-
device_id?: string;
|
|
10
|
-
push_id?: string;
|
|
11
|
-
login_ip?: string;
|
|
12
|
-
vpa?: string;
|
|
13
|
-
referral_code?: string;
|
|
14
|
-
token?: string;
|
|
15
|
-
email?: string;
|
|
16
|
-
biometric_enabled?: boolean;
|
|
17
|
-
status?: string;
|
|
18
|
-
is_deleted?: boolean;
|
|
19
|
-
created_at?: Date;
|
|
20
|
-
updated_at?: Date;
|
|
21
|
-
}
|
|
22
|
-
export interface EqxCustomerModel extends EqxCustomersTable, RowDataPacket {
|
|
23
|
-
}
|
|
24
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { RowDataPacket } from "mysql2";
|
|
2
|
-
export declare enum StatusEnum {
|
|
3
|
-
Pending = "pending",
|
|
4
|
-
Success = "success"
|
|
5
|
-
}
|
|
6
|
-
export declare enum YesNoEnum {
|
|
7
|
-
Y = "Y",
|
|
8
|
-
N = "N"
|
|
9
|
-
}
|
|
10
|
-
export interface DeviceBindingTable {
|
|
11
|
-
id: number;
|
|
12
|
-
customer_id: number;
|
|
13
|
-
device_id: string;
|
|
14
|
-
sim_no?: string | null;
|
|
15
|
-
sim_network?: string | null;
|
|
16
|
-
status: StatusEnum;
|
|
17
|
-
is_active: YesNoEnum;
|
|
18
|
-
created_at?: Date | null;
|
|
19
|
-
updated_at?: Date | null;
|
|
20
|
-
}
|
|
21
|
-
export interface DeviceBindingModel extends DeviceBindingTable, RowDataPacket {
|
|
22
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.YesNoEnum = exports.StatusEnum = void 0;
|
|
4
|
-
var StatusEnum;
|
|
5
|
-
(function (StatusEnum) {
|
|
6
|
-
StatusEnum["Pending"] = "pending";
|
|
7
|
-
StatusEnum["Success"] = "success";
|
|
8
|
-
})(StatusEnum || (exports.StatusEnum = StatusEnum = {}));
|
|
9
|
-
var YesNoEnum;
|
|
10
|
-
(function (YesNoEnum) {
|
|
11
|
-
YesNoEnum["Y"] = "Y";
|
|
12
|
-
YesNoEnum["N"] = "N";
|
|
13
|
-
})(YesNoEnum || (exports.YesNoEnum = YesNoEnum = {}));
|
package/models/RewardsOffer.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { RowDataPacket } from 'mysql2';
|
|
2
|
-
interface Offers {
|
|
3
|
-
id: number;
|
|
4
|
-
title: string;
|
|
5
|
-
description: string;
|
|
6
|
-
offer_code: string;
|
|
7
|
-
category_id: number;
|
|
8
|
-
total_limit: number;
|
|
9
|
-
user_daily_limit: number;
|
|
10
|
-
user_weekly_limit: number;
|
|
11
|
-
user_monthly_limit: number;
|
|
12
|
-
backup_offer_id: number | null;
|
|
13
|
-
tier: number | null;
|
|
14
|
-
reward_type_id: number;
|
|
15
|
-
reward_nature: string;
|
|
16
|
-
min_value: number;
|
|
17
|
-
max_value: number;
|
|
18
|
-
probability: JSON;
|
|
19
|
-
created_at: Date;
|
|
20
|
-
updated_at: Date;
|
|
21
|
-
}
|
|
22
|
-
interface OfferCodeUsage {
|
|
23
|
-
id: number;
|
|
24
|
-
offer_id: number;
|
|
25
|
-
user_id: number;
|
|
26
|
-
created_at: Date;
|
|
27
|
-
updated_at: Date;
|
|
28
|
-
}
|
|
29
|
-
export interface OffersModel extends Offers, RowDataPacket {
|
|
30
|
-
}
|
|
31
|
-
export interface OfferCodeUsageModel extends OfferCodeUsage, RowDataPacket {
|
|
32
|
-
}
|
|
33
|
-
export {};
|
package/models/RewardsOffer.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { RowDataPacket } from 'mysql2';
|
|
2
|
-
export interface WealthWebhookTable {
|
|
3
|
-
id?: number;
|
|
4
|
-
customer_id?: number;
|
|
5
|
-
gateway_id?: string;
|
|
6
|
-
event_type?: string;
|
|
7
|
-
event_property?: string;
|
|
8
|
-
event_status?: string;
|
|
9
|
-
webhook_data?: string;
|
|
10
|
-
created_at?: Date;
|
|
11
|
-
updated_at?: Date;
|
|
12
|
-
}
|
|
13
|
-
export interface WealthWebhookModel extends WealthWebhookTable, RowDataPacket {
|
|
14
|
-
}
|
package/models/WealthWebhook.js
DELETED