@stashfin/mysql2 1.3.4 → 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/models/StashCash.d.ts +3 -2
- package/package.json +1 -1
- package/index copy.d.ts +0 -17
- package/index copy.js +0 -73
package/models/StashCash.d.ts
CHANGED
|
@@ -23,8 +23,9 @@ export interface StashCashTrascationTable {
|
|
|
23
23
|
locked: number;
|
|
24
24
|
unlocked: number;
|
|
25
25
|
remaining: number;
|
|
26
|
-
txn_type: 'debit' | 'credit'
|
|
27
|
-
|
|
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
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;
|