This commit is contained in:
Benjamin Toby
2025-08-02 07:44:30 +01:00
parent 1f375fe94f
commit 9ca64cf25e
12 changed files with 108 additions and 212 deletions
@@ -0,0 +1,6 @@
import { ConnectionConfig } from "mariadb";
import { DsqlConnectionParam } from "../types";
/**
* # Grab General CONNECTION for DSQL
*/
export default function grabDSQLConnectionConfig(param?: DsqlConnectionParam): ConnectionConfig;
@@ -0,0 +1,18 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabDSQLConnectionConfig;
const grabDbSSL_1 = __importDefault(require("./backend/grabDbSSL"));
/**
* # Grab General CONNECTION for DSQL
*/
function grabDSQLConnectionConfig(param) {
const CONN_TIMEOUT = 10000;
const config = Object.assign({ host: process.env.DSQL_DB_HOST, user: process.env.DSQL_DB_USERNAME, password: process.env.DSQL_DB_PASSWORD, database: (param === null || param === void 0 ? void 0 : param.database) ||
((param === null || param === void 0 ? void 0 : param.noDb) ? undefined : process.env.DSQL_DB_NAME), port: process.env.DSQL_DB_PORT
? Number(process.env.DSQL_DB_PORT)
: undefined, charset: "utf8mb4", ssl: (0, grabDbSSL_1.default)(), bigIntAsNumber: true, supportBigNumbers: true, bigNumberStrings: false, dateStrings: true, metaAsArray: true, socketTimeout: CONN_TIMEOUT, connectTimeout: CONN_TIMEOUT, compress: true }, param === null || param === void 0 ? void 0 : param.config);
return config;
}
+3 -17
View File
@@ -1,20 +1,6 @@
import { Connection, ConnectionConfig } from "mariadb";
type Param = {
/**
* No Database Connection
*/
noDb?: boolean;
/**
* Database Name
*/
database?: string;
/**
* Debug
*/
config?: ConnectionConfig;
};
import { Connection } from "mariadb";
import { DsqlConnectionParam } from "../types";
/**
* # Grab General CONNECTION for DSQL
*/
export default function grabDSQLConnection(param?: Param): Promise<Connection>;
export {};
export default function grabDSQLConnection(param?: DsqlConnectionParam): Promise<Connection>;
+2 -78
View File
@@ -14,17 +14,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabDSQLConnection;
const mariadb_1 = __importDefault(require("mariadb"));
const grabDbSSL_1 = __importDefault(require("./backend/grabDbSSL"));
const grab_dsql_connection_config_1 = __importDefault(require("./grab-dsql-connection-config"));
/**
* # Grab General CONNECTION for DSQL
*/
function grabDSQLConnection(param) {
return __awaiter(this, void 0, void 0, function* () {
const CONN_TIMEOUT = 10000;
const config = Object.assign({ host: process.env.DSQL_DB_HOST, user: process.env.DSQL_DB_USERNAME, password: process.env.DSQL_DB_PASSWORD, database: (param === null || param === void 0 ? void 0 : param.database) ||
((param === null || param === void 0 ? void 0 : param.noDb) ? undefined : process.env.DSQL_DB_NAME), port: process.env.DSQL_DB_PORT
? Number(process.env.DSQL_DB_PORT)
: undefined, charset: "utf8mb4", ssl: (0, grabDbSSL_1.default)(), bigIntAsNumber: true, supportBigNumbers: true, bigNumberStrings: false, dateStrings: true, metaAsArray: true, socketTimeout: CONN_TIMEOUT, connectTimeout: CONN_TIMEOUT, compress: true }, param === null || param === void 0 ? void 0 : param.config);
const config = (0, grab_dsql_connection_config_1.default)(param);
try {
return yield mariadb_1.default.createConnection(config);
}
@@ -32,77 +28,5 @@ function grabDSQLConnection(param) {
console.log(`Error Grabbing DSQL Connection =>`, config);
throw error;
}
// if (global.DSQL_USE_LOCAL || param?.local) {
// return (
// global.DSQL_DB_CONN ||
// (await mariadb.createConnection({
// host: process.env.DSQL_DB_HOST,
// user: process.env.DSQL_DB_USERNAME,
// password: process.env.DSQL_DB_PASSWORD,
// 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(),
// supportBigNumbers: true,
// bigNumberStrings: false,
// dateStrings: true,
// }))
// );
// }
// if (param?.ro) {
// return (
// global.DSQL_READ_ONLY_DB_CONN ||
// (await mariadb.createConnection({
// host: process.env.DSQL_DB_HOST,
// user: process.env.DSQL_DB_READ_ONLY_USERNAME,
// password: process.env.DSQL_DB_READ_ONLY_PASSWORD,
// port: process.env.DSQL_DB_PORT
// ? Number(process.env.DSQL_DB_PORT)
// : undefined,
// charset: "utf8mb4",
// ssl: grabDbSSL(),
// supportBigNumbers: true,
// bigNumberStrings: false,
// dateStrings: true,
// }))
// );
// }
// if (param?.fa) {
// return (
// global.DSQL_FULL_ACCESS_DB_CONN ||
// (await mariadb.createConnection({
// host: process.env.DSQL_DB_HOST,
// user: process.env.DSQL_DB_FULL_ACCESS_USERNAME,
// password: process.env.DSQL_DB_FULL_ACCESS_PASSWORD,
// port: process.env.DSQL_DB_PORT
// ? Number(process.env.DSQL_DB_PORT)
// : undefined,
// charset: "utf8mb4",
// ssl: grabDbSSL(),
// supportBigNumbers: true,
// bigNumberStrings: false,
// dateStrings: true,
// }))
// );
// }
// return (
// global.DSQL_DB_CONN ||
// (await mariadb.createConnection({
// host: process.env.DSQL_DB_HOST,
// user: process.env.DSQL_DB_USERNAME,
// password: process.env.DSQL_DB_PASSWORD,
// 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(),
// supportBigNumbers: true,
// bigNumberStrings: false,
// dateStrings: true,
// }))
// );
});
}