Updates
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { ConnectionConfig } from "mariadb";
|
||||
import grabDbSSL from "./backend/grabDbSSL";
|
||||
import { DsqlConnectionParam } from "../types";
|
||||
|
||||
/**
|
||||
* # Grab General CONNECTION for DSQL
|
||||
*/
|
||||
export default function grabDSQLConnectionConfig(
|
||||
param?: DsqlConnectionParam
|
||||
): ConnectionConfig {
|
||||
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,
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
@@ -1,51 +1,15 @@
|
||||
import mariadb, { Connection, ConnectionConfig } from "mariadb";
|
||||
import grabDbSSL from "./backend/grabDbSSL";
|
||||
|
||||
type Param = {
|
||||
/**
|
||||
* No Database Connection
|
||||
*/
|
||||
noDb?: boolean;
|
||||
/**
|
||||
* Database Name
|
||||
*/
|
||||
database?: string;
|
||||
/**
|
||||
* Debug
|
||||
*/
|
||||
config?: ConnectionConfig;
|
||||
};
|
||||
import { DsqlConnectionParam } from "../types";
|
||||
import grabDSQLConnectionConfig from "./grab-dsql-connection-config";
|
||||
|
||||
/**
|
||||
* # Grab General CONNECTION for DSQL
|
||||
*/
|
||||
export default async function grabDSQLConnection(
|
||||
param?: Param
|
||||
param?: DsqlConnectionParam
|
||||
): Promise<Connection> {
|
||||
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 = grabDSQLConnectionConfig(param);
|
||||
|
||||
try {
|
||||
return await mariadb.createConnection(config);
|
||||
@@ -53,80 +17,4 @@ export default async function grabDSQLConnection(
|
||||
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,
|
||||
// }))
|
||||
// );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user