Updates
This commit is contained in:
@@ -2,13 +2,15 @@ import fs from "fs";
|
||||
import grabDirNames from "./names/grab-dir-names";
|
||||
import type { ConnectionConfig } from "mariadb";
|
||||
import path from "path";
|
||||
import serverlessMysql from "serverless-mysql";
|
||||
import { ConnectionOptions } from "tls";
|
||||
|
||||
type Return = ConnectionConfig["ssl"] | undefined;
|
||||
// type Return = ConnectionConfig["ssl"] | undefined;
|
||||
|
||||
/**
|
||||
* # Grab SSL
|
||||
*/
|
||||
export default function grabDbSSL(): Return {
|
||||
export default function grabDbSSL(): any {
|
||||
let maxscaleSSLCaCertFileFinal;
|
||||
|
||||
try {
|
||||
|
||||
@@ -43,10 +43,10 @@ export default async function connDbHandler<ReturnType = any>(
|
||||
let queryErrorArray: DSQLErrorObject[] = [];
|
||||
|
||||
if (typeof query == "string") {
|
||||
const [results] = await finalConnection.query(
|
||||
const results = (await finalConnection.query(
|
||||
trimQuery(query),
|
||||
values
|
||||
);
|
||||
)) as any;
|
||||
|
||||
if (debug) {
|
||||
debugLog({
|
||||
@@ -74,7 +74,7 @@ export default async function connDbHandler<ReturnType = any>(
|
||||
queryObj.values
|
||||
);
|
||||
|
||||
const results = queryObjRes[0];
|
||||
const results = queryObjRes;
|
||||
|
||||
if (debug) {
|
||||
debugLog({
|
||||
@@ -106,7 +106,7 @@ export default async function connDbHandler<ReturnType = any>(
|
||||
};
|
||||
}
|
||||
|
||||
return resArray;
|
||||
return resArray as ReturnType;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import mysql from "mysql";
|
||||
|
||||
/**
|
||||
* # End MYSQL Connection
|
||||
*/
|
||||
function endConnection(connection: mysql.Connection) {
|
||||
if (connection.state !== "disconnected") {
|
||||
connection.end((err) => {
|
||||
console.log(err?.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default endConnection;
|
||||
@@ -1,37 +1,43 @@
|
||||
import { ConnectionConfig } from "mariadb";
|
||||
import grabDbSSL from "./backend/grabDbSSL";
|
||||
import { DsqlConnectionParam } from "../types";
|
||||
import serverlessMysql from "serverless-mysql";
|
||||
import { ConnectionOptions } from "tls";
|
||||
import _ from "lodash";
|
||||
|
||||
/**
|
||||
* # Grab General CONNECTION for DSQL
|
||||
*/
|
||||
export default function grabDSQLConnectionConfig(
|
||||
param?: DsqlConnectionParam
|
||||
): ConnectionConfig {
|
||||
): serverlessMysql.Config {
|
||||
const CONN_TIMEOUT = 10000;
|
||||
|
||||
const config: ConnectionConfig = {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database:
|
||||
param?.database ||
|
||||
(param?.noDb ? undefined : process.env.DSQL_DB_NAME),
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
ssl: grabDbSSL(),
|
||||
bigIntAsNumber: true,
|
||||
supportBigNumbers: true,
|
||||
bigNumberStrings: false,
|
||||
dateStrings: true,
|
||||
metaAsArray: true,
|
||||
socketTimeout: CONN_TIMEOUT,
|
||||
connectTimeout: CONN_TIMEOUT,
|
||||
compress: true,
|
||||
...param?.config,
|
||||
const config: serverlessMysql.Config = {
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database:
|
||||
param?.database ||
|
||||
(param?.noDb ? undefined : process.env.DSQL_DB_NAME),
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
ssl: grabDbSSL(),
|
||||
connectTimeout: CONN_TIMEOUT,
|
||||
dateStrings: true,
|
||||
compress: true,
|
||||
decimalNumbers: true,
|
||||
// supportBigNumbers: true,
|
||||
// bigNumberStrings: false,
|
||||
// bigIntAsNumber: true,
|
||||
// metaAsArray: true,
|
||||
// socketTimeout: CONN_TIMEOUT,
|
||||
// ...param?.config,
|
||||
},
|
||||
};
|
||||
|
||||
return config;
|
||||
return _.merge(config, param?.config);
|
||||
}
|
||||
|
||||
@@ -2,17 +2,19 @@ import mariadb, { Connection, ConnectionConfig } from "mariadb";
|
||||
import grabDbSSL from "./backend/grabDbSSL";
|
||||
import { DsqlConnectionParam } from "../types";
|
||||
import grabDSQLConnectionConfig from "./grab-dsql-connection-config";
|
||||
import serverlessMysql, { ServerlessMysql } from "serverless-mysql";
|
||||
|
||||
/**
|
||||
* # Grab General CONNECTION for DSQL
|
||||
*/
|
||||
export default async function grabDSQLConnection(
|
||||
param?: DsqlConnectionParam
|
||||
): Promise<Connection> {
|
||||
): Promise<ServerlessMysql> {
|
||||
const config = grabDSQLConnectionConfig(param);
|
||||
|
||||
try {
|
||||
return await mariadb.createConnection(config);
|
||||
const sql = serverlessMysql(config);
|
||||
return sql;
|
||||
} catch (error) {
|
||||
console.log(`Error Grabbing DSQL Connection =>`, config);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user