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

2
dist/index.d.ts vendored
View File

@ -22,6 +22,7 @@ import dbHandler from "./package-shared/functions/backend/dbHandler";
import httpsRequest from "./package-shared/functions/backend/httpsRequest"; import httpsRequest from "./package-shared/functions/backend/httpsRequest";
import handleNodemailer from "./package-shared/functions/backend/handleNodemailer"; import handleNodemailer from "./package-shared/functions/backend/handleNodemailer";
import grabDSQLConnection from "./package-shared/utils/grab-dsql-connection"; import grabDSQLConnection from "./package-shared/utils/grab-dsql-connection";
import grabDSQLConnectionConfig from "./package-shared/utils/grab-dsql-connection-config";
/** /**
* Main Export * Main Export
*/ */
@ -136,6 +137,7 @@ declare const datasquirel: {
httpsRequest: typeof httpsRequest; httpsRequest: typeof httpsRequest;
httpRequest: typeof httpsRequest; httpRequest: typeof httpsRequest;
grabDSQLConnection: typeof grabDSQLConnection; grabDSQLConnection: typeof grabDSQLConnection;
grabDSQLConnectionConfig: typeof grabDSQLConnectionConfig;
}; };
/** /**
* Run Crud actions `get`, `insert`, `update`, `delete` * Run Crud actions `get`, `insert`, `update`, `delete`

2
dist/index.js vendored
View File

@ -28,6 +28,7 @@ const dbHandler_1 = __importDefault(require("./package-shared/functions/backend/
const httpsRequest_1 = __importDefault(require("./package-shared/functions/backend/httpsRequest")); const httpsRequest_1 = __importDefault(require("./package-shared/functions/backend/httpsRequest"));
const handleNodemailer_1 = __importDefault(require("./package-shared/functions/backend/handleNodemailer")); const handleNodemailer_1 = __importDefault(require("./package-shared/functions/backend/handleNodemailer"));
const grab_dsql_connection_1 = __importDefault(require("./package-shared/utils/grab-dsql-connection")); const grab_dsql_connection_1 = __importDefault(require("./package-shared/utils/grab-dsql-connection"));
const grab_dsql_connection_config_1 = __importDefault(require("./package-shared/utils/grab-dsql-connection-config"));
/** /**
* API Functions Object * API Functions Object
*/ */
@ -78,6 +79,7 @@ const datasquirel = {
httpsRequest: httpsRequest_1.default, httpsRequest: httpsRequest_1.default,
httpRequest: httpsRequest_1.default, httpRequest: httpsRequest_1.default,
grabDSQLConnection: grab_dsql_connection_1.default, grabDSQLConnection: grab_dsql_connection_1.default,
grabDSQLConnectionConfig: grab_dsql_connection_config_1.default,
}, },
/** /**
* Run Crud actions `get`, `insert`, `update`, `delete` * Run Crud actions `get`, `insert`, `update`, `delete`

View File

@ -5,6 +5,7 @@ import type sharp from "sharp";
import type DataTypes from "../data/data-types"; import type DataTypes from "../data/data-types";
import type { IncomingMessage, ServerResponse } from "http"; import type { IncomingMessage, ServerResponse } from "http";
import type { CookieNames } from "../dict/cookie-names"; import type { CookieNames } from "../dict/cookie-names";
import { ConnectionConfig } from "mariadb";
export type DSQL_DatabaseFullName = string; export type DSQL_DatabaseFullName = string;
export type DSQL_DATASQUIREL_USER_BACKUPS_JOIN = DSQL_DATASQUIREL_BACKUPS & { export type DSQL_DATASQUIREL_USER_BACKUPS_JOIN = DSQL_DATASQUIREL_BACKUPS & {
[k in (typeof UserSelectFields)[number]["alias"]]?: string; [k in (typeof UserSelectFields)[number]["alias"]]?: string;
@ -2085,4 +2086,18 @@ export type AIComponentProps = {
targetAI: AIOptionsObject; targetAI: AIOptionsObject;
context: any[]; context: any[];
}; };
export type DsqlConnectionParam = {
/**
* No Database Connection
*/
noDb?: boolean;
/**
* Database Name
*/
database?: string;
/**
* Debug
*/
config?: ConnectionConfig;
};
export {}; export {};

View File

@ -0,0 +1,6 @@
import { ConnectionConfig } from "mariadb";
import { DsqlConnectionParam } from "../types";
/**
* # Grab General CONNECTION for DSQL
*/
export default function grabDSQLConnectionConfig(param?: DsqlConnectionParam): ConnectionConfig;

View File

@ -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;
}

View File

@ -1,20 +1,6 @@
import { Connection, ConnectionConfig } from "mariadb"; import { Connection } from "mariadb";
type Param = { import { DsqlConnectionParam } from "../types";
/**
* No Database Connection
*/
noDb?: boolean;
/**
* Database Name
*/
database?: string;
/**
* Debug
*/
config?: ConnectionConfig;
};
/** /**
* # Grab General CONNECTION for DSQL * # Grab General CONNECTION for DSQL
*/ */
export default function grabDSQLConnection(param?: Param): Promise<Connection>; export default function grabDSQLConnection(param?: DsqlConnectionParam): Promise<Connection>;
export {};

View File

@ -14,17 +14,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabDSQLConnection; exports.default = grabDSQLConnection;
const mariadb_1 = __importDefault(require("mariadb")); 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 * # Grab General CONNECTION for DSQL
*/ */
function grabDSQLConnection(param) { function grabDSQLConnection(param) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const CONN_TIMEOUT = 10000; const config = (0, grab_dsql_connection_config_1.default)(param);
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);
try { try {
return yield mariadb_1.default.createConnection(config); return yield mariadb_1.default.createConnection(config);
} }
@ -32,77 +28,5 @@ function grabDSQLConnection(param) {
console.log(`Error Grabbing DSQL Connection =>`, config); console.log(`Error Grabbing DSQL Connection =>`, config);
throw error; 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,
// }))
// );
}); });
} }

View File

@ -29,6 +29,7 @@ import dbHandler from "./package-shared/functions/backend/dbHandler";
import httpsRequest from "./package-shared/functions/backend/httpsRequest"; import httpsRequest from "./package-shared/functions/backend/httpsRequest";
import handleNodemailer from "./package-shared/functions/backend/handleNodemailer"; import handleNodemailer from "./package-shared/functions/backend/handleNodemailer";
import grabDSQLConnection from "./package-shared/utils/grab-dsql-connection"; import grabDSQLConnection from "./package-shared/utils/grab-dsql-connection";
import grabDSQLConnectionConfig from "./package-shared/utils/grab-dsql-connection-config";
/** /**
* API Functions Object * API Functions Object
@ -82,6 +83,7 @@ const datasquirel = {
httpsRequest, httpsRequest,
httpRequest: httpsRequest, httpRequest: httpsRequest,
grabDSQLConnection, grabDSQLConnection,
grabDSQLConnectionConfig,
}, },
/** /**
* Run Crud actions `get`, `insert`, `update`, `delete` * Run Crud actions `get`, `insert`, `update`, `delete`

View File

@ -22,6 +22,7 @@ import type sharp from "sharp";
import type DataTypes from "../data/data-types"; import type DataTypes from "../data/data-types";
import type { IncomingMessage, ServerResponse } from "http"; import type { IncomingMessage, ServerResponse } from "http";
import type { CookieNames } from "../dict/cookie-names"; import type { CookieNames } from "../dict/cookie-names";
import { ConnectionConfig } from "mariadb";
export type DSQL_DatabaseFullName = string; export type DSQL_DatabaseFullName = string;
@ -2722,3 +2723,18 @@ export type AIComponentProps = {
targetAI: AIOptionsObject; targetAI: AIOptionsObject;
context: any[]; context: any[];
}; };
export type DsqlConnectionParam = {
/**
* No Database Connection
*/
noDb?: boolean;
/**
* Database Name
*/
database?: string;
/**
* Debug
*/
config?: ConnectionConfig;
};

View File

@ -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;
}

View File

@ -1,51 +1,15 @@
import mariadb, { Connection, ConnectionConfig } from "mariadb"; import mariadb, { Connection, ConnectionConfig } from "mariadb";
import grabDbSSL from "./backend/grabDbSSL"; import grabDbSSL from "./backend/grabDbSSL";
import { DsqlConnectionParam } from "../types";
type Param = { import grabDSQLConnectionConfig from "./grab-dsql-connection-config";
/**
* No Database Connection
*/
noDb?: boolean;
/**
* Database Name
*/
database?: string;
/**
* Debug
*/
config?: ConnectionConfig;
};
/** /**
* # Grab General CONNECTION for DSQL * # Grab General CONNECTION for DSQL
*/ */
export default async function grabDSQLConnection( export default async function grabDSQLConnection(
param?: Param param?: DsqlConnectionParam
): Promise<Connection> { ): Promise<Connection> {
const CONN_TIMEOUT = 10000; const config = grabDSQLConnectionConfig(param);
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,
};
try { try {
return await mariadb.createConnection(config); return await mariadb.createConnection(config);
@ -53,80 +17,4 @@ export default async function grabDSQLConnection(
console.log(`Error Grabbing DSQL Connection =>`, config); console.log(`Error Grabbing DSQL Connection =>`, config);
throw error; 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,
// }))
// );
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "5.1.2", "version": "5.1.3",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {