108 lines
5.2 KiB
JavaScript
108 lines
5.2 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.default = grabDSQLConnection;
|
|
const mariadb_1 = __importDefault(require("mariadb"));
|
|
const grabDbSSL_1 = __importDefault(require("./backend/grabDbSSL"));
|
|
/**
|
|
* # Grab General CONNECTION for DSQL
|
|
*/
|
|
function grabDSQLConnection(param) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
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 }, param === null || param === void 0 ? void 0 : param.config);
|
|
try {
|
|
return yield mariadb_1.default.createConnection(config);
|
|
}
|
|
catch (error) {
|
|
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,
|
|
// }))
|
|
// );
|
|
});
|
|
}
|