Updates
This commit is contained in:
Vendored
+1
-1
@@ -40,7 +40,7 @@ declare const datasquirelClient: {
|
||||
} | {
|
||||
[s: string]: any;
|
||||
}[] | undefined;
|
||||
stringify: (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number) => string | undefined;
|
||||
stringify: (value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number) => string | undefined;
|
||||
};
|
||||
numberfy: typeof numberfy;
|
||||
slugify: typeof slugify;
|
||||
|
||||
Vendored
+3
-1
@@ -25,6 +25,7 @@ import sqlDeleteGenerator from "./package-shared/functions/dsql/sql/sql-delete-g
|
||||
import trimSql from "./package-shared/utils/trim-sql";
|
||||
import parseCookies from "./package-shared/utils/backend/parseCookies";
|
||||
import httpRequest from "./package-shared/functions/backend/httpRequest";
|
||||
import connDbHandler from "./package-shared/utils/db/conn-db-handler";
|
||||
/**
|
||||
* Main Export
|
||||
*/
|
||||
@@ -83,7 +84,7 @@ declare const datasquirel: {
|
||||
} | {
|
||||
[s: string]: any;
|
||||
}[] | undefined;
|
||||
stringify: (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number) => string | undefined;
|
||||
stringify: (value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number) => string | undefined;
|
||||
};
|
||||
numberfy: typeof import("./package-shared/utils/numberfy").default;
|
||||
slugify: typeof import("./package-shared/utils/slugify").default;
|
||||
@@ -103,6 +104,7 @@ declare const datasquirel: {
|
||||
};
|
||||
parseCookies: typeof parseCookies;
|
||||
httpRequest: typeof httpRequest;
|
||||
connDbHandler: typeof connDbHandler;
|
||||
};
|
||||
};
|
||||
export default datasquirel;
|
||||
|
||||
Vendored
+2
@@ -32,6 +32,7 @@ const sql_delete_generator_1 = __importDefault(require("./package-shared/functio
|
||||
const trim_sql_1 = __importDefault(require("./package-shared/utils/trim-sql"));
|
||||
const parseCookies_1 = __importDefault(require("./package-shared/utils/backend/parseCookies"));
|
||||
const httpRequest_1 = __importDefault(require("./package-shared/functions/backend/httpRequest"));
|
||||
const conn_db_handler_1 = __importDefault(require("./package-shared/utils/db/conn-db-handler"));
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
@@ -92,6 +93,7 @@ const datasquirel = {
|
||||
},
|
||||
parseCookies: parseCookies_1.default,
|
||||
httpRequest: httpRequest_1.default,
|
||||
connDbHandler: conn_db_handler_1.default,
|
||||
},
|
||||
};
|
||||
exports.default = datasquirel;
|
||||
|
||||
@@ -55,7 +55,7 @@ function githubLogin(_a) {
|
||||
}
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
console.log("ERROR in githubLogin.js backend function =>", error.message);
|
||||
console.log("ERROR in githubLogin.ts backend function =>", error.message);
|
||||
}
|
||||
return gitHubUser;
|
||||
});
|
||||
|
||||
@@ -182,16 +182,16 @@ function handleSocialDb(_a) {
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.log("Social User Failed to insert in 'handleSocialDb.js' backend function =>", newUser);
|
||||
console.log("Social User Failed to insert in 'handleSocialDb.ts' backend function =>", newUser);
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
msg: "Social User Failed to insert in 'handleSocialDb.js' backend function",
|
||||
msg: "Social User Failed to insert in 'handleSocialDb.ts' backend function",
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log("ERROR in 'handleSocialDb.js' backend function =>", error.message);
|
||||
console.log("ERROR in 'handleSocialDb.ts' backend function =>", error.message);
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
|
||||
@@ -88,7 +88,7 @@ function apiGoogleLogin(_a) {
|
||||
return Object.assign({}, loggedInGoogleUser);
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
console.log(`apo-google-login.js ERROR: ${error.message}`);
|
||||
console.log(`api-google-login.ts ERROR: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
payload: undefined,
|
||||
|
||||
@@ -71,7 +71,7 @@ function addUsersTableToDb(_a) {
|
||||
return `Done!`;
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
||||
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
|
||||
(0, serverError_1.default)({
|
||||
component: "addUsersTableToDb",
|
||||
message: error.message,
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
* @description this function takes in a text(or number) and returns a sanitized
|
||||
* text, usually without spaces
|
||||
*/
|
||||
declare function sanitizeSql(text: any, spaces: boolean, regex?: RegExp | null): any;
|
||||
declare function sanitizeSql(text: any, spaces?: boolean, regex?: RegExp | null): any;
|
||||
export default sanitizeSql;
|
||||
|
||||
@@ -32,7 +32,7 @@ function grabNewUsersTableSchema(params) {
|
||||
return userPreset;
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
console.log(`grabNewUsersTableSchema.js ERROR: ${error.message}`);
|
||||
console.log(`grabNewUsersTableSchema.ts ERROR: ${error.message}`);
|
||||
(0, serverError_1.default)({
|
||||
component: "grabNewUsersTableSchema",
|
||||
message: error.message,
|
||||
|
||||
@@ -56,9 +56,9 @@ function grabSchemaFieldsFromData({ data, fields, excludeData, excludeFields, })
|
||||
return finalFields;
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
console.log(`grabSchemaFieldsFromData.js ERROR: ${error.message}`);
|
||||
console.log(`grabSchemaFieldsFromData.ts ERROR: ${error.message}`);
|
||||
(0, serverError_1.default)({
|
||||
component: "grabSchemaFieldsFromData.js",
|
||||
component: "grabSchemaFieldsFromData.ts",
|
||||
message: error.message,
|
||||
});
|
||||
return [];
|
||||
|
||||
@@ -52,7 +52,7 @@ function updateUsersTableSchema(_a) {
|
||||
return `Done!`;
|
||||
}
|
||||
catch (error) {
|
||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
||||
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
|
||||
(0, serverError_1.default)({
|
||||
component: "addUsersTableToDb",
|
||||
message: error.message,
|
||||
|
||||
@@ -41,4 +41,3 @@ function encrypt({ data, encryptionKey, encryptionSalt, }) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
module.exports = encrypt;
|
||||
|
||||
+22
-3
@@ -15,20 +15,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = createDbFromSchema;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
require("dotenv").config({ path: "./../.env" });
|
||||
const noDatabaseDbHandler_1 = __importDefault(require("./utils/noDatabaseDbHandler"));
|
||||
const varDatabaseDbHandler_1 = __importDefault(require("./utils/varDatabaseDbHandler"));
|
||||
const createTable_1 = __importDefault(require("./utils/createTable"));
|
||||
const updateTable_1 = __importDefault(require("./utils/updateTable"));
|
||||
const dbHandler_1 = __importDefault(require("./utils/dbHandler"));
|
||||
const ejson_1 = __importDefault(require("../utils/ejson"));
|
||||
const execFlag = process.argv.find((arg) => arg === "--exec");
|
||||
const util_1 = require("util");
|
||||
/**
|
||||
* # Create database from Schema Function
|
||||
*/
|
||||
function createDbFromSchema(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ userId, targetDatabase, dbSchemaData, }) {
|
||||
var _b, _c;
|
||||
console.log("///////////////////////////////");
|
||||
console.log("///////////////////////////////");
|
||||
console.log("Rebuilding Database ...");
|
||||
console.log("process.env.DSQL_DB_HOST", process.env.DSQL_DB_HOST);
|
||||
console.log("process.env.DSQL_DB_USERNAME", process.env.DSQL_DB_USERNAME);
|
||||
console.log("process.env.DSQL_DB_PASSWORD", process.env.DSQL_DB_PASSWORD);
|
||||
console.log("process.env.DSQL_DB_NAME", process.env.DSQL_DB_NAME);
|
||||
const schemaPath = userId
|
||||
? path_1.default.join(String(process.env.DSQL_USER_DB_SCHEMA_PATH), `/user-${userId}/main.json`)
|
||||
: path_1.default.resolve(__dirname, "../../jsonData/dbSchemas/main.json");
|
||||
@@ -46,8 +52,10 @@ function createDbFromSchema(_a) {
|
||||
if (targetDatabase && dbFullName != targetDatabase) {
|
||||
continue;
|
||||
}
|
||||
console.log("Checking Database ...");
|
||||
/** @type {any} */
|
||||
const dbCheck = yield (0, noDatabaseDbHandler_1.default)(`SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${dbFullName}'`);
|
||||
console.log("DB Checked Success!");
|
||||
if (dbCheck && ((_b = dbCheck[0]) === null || _b === void 0 ? void 0 : _b.dbFullName)) {
|
||||
// Database Exists
|
||||
}
|
||||
@@ -238,8 +246,19 @@ function createDbFromSchema(_a) {
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log("Database Successfully Rebuilt!");
|
||||
console.log("///////////////////////////////");
|
||||
console.log("///////////////////////////////");
|
||||
});
|
||||
}
|
||||
if (execFlag) {
|
||||
const { values } = (0, util_1.parseArgs)({
|
||||
args: process.argv,
|
||||
options: {
|
||||
exec: { type: "boolean" },
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
});
|
||||
if (values.exec) {
|
||||
createDbFromSchema({});
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ for (let i = 0; i < sourceFiles.length; i++) {
|
||||
const srcFolder = sourceFiles[i];
|
||||
const dstFile = dstFiles[i];
|
||||
fs_1.default.watch(srcFolder, { recursive: true }, (evtType, prev) => {
|
||||
if ((prev === null || prev === void 0 ? void 0 : prev.match(/\(/)) || (prev === null || prev === void 0 ? void 0 : prev.match(/\.js$/i))) {
|
||||
if ((prev === null || prev === void 0 ? void 0 : prev.match(/\(/)) || (prev === null || prev === void 0 ? void 0 : prev.match(/\.(j|t)s$/i))) {
|
||||
return;
|
||||
}
|
||||
let finalSrcPath = `${srcFolder}/main.less`;
|
||||
|
||||
@@ -1,4 +1 @@
|
||||
/**
|
||||
* # Create database from Schema Function
|
||||
*/
|
||||
export default function noDatabaseDbHandler(queryString: string): Promise<any>;
|
||||
|
||||
@@ -14,37 +14,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = noDatabaseDbHandler;
|
||||
const dbHandler_1 = __importDefault(require("./dbHandler"));
|
||||
/**
|
||||
* # Create database from Schema Function
|
||||
*/
|
||||
function noDatabaseDbHandler(queryString) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
/** ********************* Run Query */
|
||||
results = yield (0, dbHandler_1.default)({ query: queryString });
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
catch (error) {
|
||||
console.log("ERROR in noDatabaseDbHandler =>", error.message);
|
||||
}
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
if (results) {
|
||||
return results;
|
||||
}
|
||||
|
||||
Vendored
+54
-53
@@ -117,6 +117,7 @@ export interface DSQL_MYSQL_user_databases_Type {
|
||||
db_image: string;
|
||||
db_description: string;
|
||||
active_clone: number;
|
||||
active_data: 0 | 1;
|
||||
active_clone_parent_db: string;
|
||||
remote_connected?: number;
|
||||
remote_db_full_name?: string;
|
||||
@@ -323,7 +324,7 @@ export interface MetricsType {
|
||||
export interface DashboardContextType {
|
||||
user?: UserType;
|
||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||
setTargetDatabase?: React.Dispatch<React.SetStateAction<DSQL_MYSQL_user_databases_Type>>;
|
||||
setTargetDatabase?: React.Dispatch<React.SetStateAction<DSQL_MYSQL_user_databases_Type | undefined>>;
|
||||
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
||||
metrics?: MetricsType;
|
||||
}
|
||||
@@ -375,7 +376,7 @@ export interface AddEntryContextType {
|
||||
richTextEditors: React.MutableRefObject<RichTextEditorsRefArray[]>;
|
||||
jsonTextEditors: React.MutableRefObject<JSONTextEditorsRefArray[]>;
|
||||
query: any;
|
||||
duplicateEntry?: any;
|
||||
duplicateEntry: any;
|
||||
confirmedDelegetedUser: any;
|
||||
}
|
||||
export interface UserDatabasesContextType {
|
||||
@@ -435,13 +436,13 @@ export interface SingleDatabaseContextType {
|
||||
confirmedDelegetedUser: any;
|
||||
}
|
||||
export interface ApiKeysContextType {
|
||||
user: UserType;
|
||||
apiKeys: any[];
|
||||
setApiKeys: React.Dispatch<React.SetStateAction<any[]>>;
|
||||
targetApiKey: any | null;
|
||||
setTargetApiKey: React.Dispatch<React.SetStateAction<any | null>>;
|
||||
newApiKey: any | null;
|
||||
setNewApiKey: React.Dispatch<React.SetStateAction<any | null>>;
|
||||
user?: UserType;
|
||||
apiKeys?: any[];
|
||||
setApiKeys?: React.Dispatch<React.SetStateAction<any[]>>;
|
||||
targetApiKey?: any | null;
|
||||
setTargetApiKey?: React.Dispatch<React.SetStateAction<any | null>>;
|
||||
newApiKey?: any | null;
|
||||
setNewApiKey?: React.Dispatch<React.SetStateAction<any | null>>;
|
||||
}
|
||||
export interface LoginFormContextType {
|
||||
user?: UserType | null;
|
||||
@@ -469,27 +470,27 @@ export interface DocsAsidePageObject {
|
||||
level?: number;
|
||||
}
|
||||
export interface AllUserUsersContextType {
|
||||
user: UserType;
|
||||
users: MYSQL_delegated_users_table_def[];
|
||||
targetUser: MYSQL_user_users_table_def | null;
|
||||
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | null>>;
|
||||
databases: DSQL_MYSQL_user_databases_Type[];
|
||||
pendingInvitations: MYSQL_invitations_table_def[];
|
||||
pendingInvitationsReceived: any[];
|
||||
adminUsers: any[];
|
||||
invitedAccounts: any[];
|
||||
user?: UserType;
|
||||
users?: MYSQL_delegated_users_table_def[];
|
||||
targetUser?: MYSQL_user_users_table_def | undefined;
|
||||
setTargetUser?: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | undefined>>;
|
||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||
pendingInvitations?: MYSQL_invitations_table_def[];
|
||||
pendingInvitationsReceived?: any[];
|
||||
adminUsers?: any[];
|
||||
invitedAccounts?: any[];
|
||||
}
|
||||
export interface AddSocialLoginContextType {
|
||||
user: UserType;
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
query: any;
|
||||
socialLogins: SocialLoginObjectType[];
|
||||
user?: UserType;
|
||||
database?: DSQL_MYSQL_user_databases_Type;
|
||||
query?: any;
|
||||
socialLogins?: SocialLoginObjectType[];
|
||||
}
|
||||
export interface DelegatedDbContextType {
|
||||
user: UserType;
|
||||
users: MYSQL_user_users_table_def[];
|
||||
targetUser: MYSQL_user_users_table_def | null;
|
||||
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | null>>;
|
||||
targetUser: MYSQL_user_users_table_def | undefined;
|
||||
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | undefined>>;
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
}
|
||||
export interface AddUserUserContextType {
|
||||
@@ -502,8 +503,8 @@ export interface AddUserUserContextType {
|
||||
export interface UserUsersContextType {
|
||||
user: UserType;
|
||||
users: MYSQL_user_users_table_def[];
|
||||
targetUser: MYSQL_user_users_table_def;
|
||||
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | null>>;
|
||||
targetUser?: MYSQL_user_users_table_def;
|
||||
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | undefined>>;
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
table: DSQL_TableSchemaType;
|
||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
||||
@@ -604,14 +605,14 @@ export interface UserSchemaContextType {
|
||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
||||
}
|
||||
export interface ConnectContextType {
|
||||
user: UserType;
|
||||
query: any;
|
||||
mariadbUserCred: MariaDBUserCredType;
|
||||
mariadbUsers: MYSQL_mariadb_users_table_def[];
|
||||
targetMariadbUser: MYSQL_mariadb_users_table_def | null;
|
||||
setTargetMariadbUser: React.Dispatch<React.SetStateAction<MYSQL_mariadb_users_table_def | null>>;
|
||||
refresh: number;
|
||||
setRefresh: React.Dispatch<React.SetStateAction<number>>;
|
||||
user?: UserType;
|
||||
query?: any;
|
||||
mariadbUserCred?: MariaDBUserCredType;
|
||||
mariadbUsers?: MYSQL_mariadb_users_table_def[];
|
||||
targetMariadbUser?: MYSQL_mariadb_users_table_def | null;
|
||||
setTargetMariadbUser?: React.Dispatch<React.SetStateAction<MYSQL_mariadb_users_table_def | null>>;
|
||||
refresh?: number;
|
||||
setRefresh?: React.Dispatch<React.SetStateAction<number>>;
|
||||
}
|
||||
export interface MYSQL_mariadb_users_table_def {
|
||||
id?: number;
|
||||
@@ -632,7 +633,7 @@ export interface DbContextType {
|
||||
user?: UserType;
|
||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
||||
setTargetDatabase?: React.Dispatch<React.SetStateAction<DSQL_MYSQL_user_databases_Type>>;
|
||||
setTargetDatabase?: React.Dispatch<React.SetStateAction<DSQL_MYSQL_user_databases_Type | undefined>>;
|
||||
}
|
||||
export interface MariaDBUserCredType {
|
||||
mariadb_user?: string;
|
||||
@@ -640,26 +641,26 @@ export interface MariaDBUserCredType {
|
||||
mariadb_pass?: string;
|
||||
}
|
||||
export interface AddTableContextType {
|
||||
user: UserType;
|
||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
tables: DSQL_TableSchemaType[];
|
||||
tableFields: DSQL_FieldSchemaType[];
|
||||
setTableFields: React.Dispatch<React.SetStateAction<DSQL_FieldSchemaType[]>>;
|
||||
targetField: DSQL_FieldSchemaType | null;
|
||||
setTargetField: React.Dispatch<React.SetStateAction<DSQL_FieldSchemaType | null>>;
|
||||
pageRefresh: number | null;
|
||||
setPageRefresh: React.Dispatch<React.SetStateAction<number>>;
|
||||
refreshFieldsListRef: React.MutableRefObject<React.Dispatch<React.SetStateAction<number>>>;
|
||||
query: any;
|
||||
user?: UserType;
|
||||
dbSchemaData?: DSQL_DatabaseSchemaType[];
|
||||
database?: DSQL_MYSQL_user_databases_Type;
|
||||
tables?: DSQL_TableSchemaType[];
|
||||
tableFields?: DSQL_FieldSchemaType[];
|
||||
setTableFields?: React.Dispatch<React.SetStateAction<DSQL_FieldSchemaType[]>>;
|
||||
targetField?: DSQL_FieldSchemaType | null;
|
||||
setTargetField?: React.Dispatch<React.SetStateAction<DSQL_FieldSchemaType | null>>;
|
||||
pageRefresh?: number | null;
|
||||
setPageRefresh?: React.Dispatch<React.SetStateAction<number>>;
|
||||
refreshFieldsListRef?: React.MutableRefObject<React.Dispatch<React.SetStateAction<number>> | undefined>;
|
||||
query?: any;
|
||||
}
|
||||
export interface DbSchemaContextType {
|
||||
user: UserType;
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
dbImage: string;
|
||||
setDbImage: React.Dispatch<React.SetStateAction<string>>;
|
||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
||||
tables: any[];
|
||||
user?: UserType;
|
||||
database?: DSQL_MYSQL_user_databases_Type;
|
||||
dbImage?: string;
|
||||
setDbImage?: React.Dispatch<React.SetStateAction<string>>;
|
||||
dbSchemaData?: DSQL_DatabaseSchemaType[];
|
||||
tables?: any[];
|
||||
}
|
||||
export interface DbShellContextType {
|
||||
user?: UserType;
|
||||
|
||||
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = DB_HANDLER;
|
||||
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
|
||||
const grabDbSSL_1 = __importDefault(require("../grabDbSSL"));
|
||||
const MASTER = (0, serverless_mysql_1.default)({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
@@ -25,7 +24,7 @@ const MASTER = (0, serverless_mysql_1.default)({
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
ssl: (0, grabDbSSL_1.default)(),
|
||||
// ssl: grabDbSSL(),
|
||||
},
|
||||
});
|
||||
/**
|
||||
|
||||
@@ -100,4 +100,3 @@ function DSQL_USER_DB_HANDLER({ paradigm, database, queryString, queryValues, })
|
||||
};
|
||||
}
|
||||
}
|
||||
module.exports = DSQL_USER_DB_HANDLER;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ServerlessMysql } from "serverless-mysql";
|
||||
type QueryObject = {
|
||||
query: string;
|
||||
values?: (string | number | undefined)[];
|
||||
};
|
||||
type Return<ReturnType = any> = ReturnType | null;
|
||||
/**
|
||||
* # Run Query From MySQL Connection
|
||||
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||
* setup with `serverless-mysql` npm module
|
||||
*/
|
||||
export default function connDbHandler<ReturnType = any>(
|
||||
/**
|
||||
* ServerlessMySQL Connection Object
|
||||
*/
|
||||
conn: ServerlessMysql,
|
||||
/**
|
||||
* String Or `QueryObject` Array
|
||||
*/
|
||||
query: QueryObject["query"] | QueryObject[],
|
||||
/**
|
||||
* Array of Values to Sanitize and Inject
|
||||
*/
|
||||
values?: QueryObject["values"]): Promise<Return<ReturnType>>;
|
||||
export {};
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
"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());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = connDbHandler;
|
||||
/**
|
||||
* # Run Query From MySQL Connection
|
||||
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||
* setup with `serverless-mysql` npm module
|
||||
*/
|
||||
function connDbHandler(
|
||||
/**
|
||||
* ServerlessMySQL Connection Object
|
||||
*/
|
||||
conn,
|
||||
/**
|
||||
* String Or `QueryObject` Array
|
||||
*/
|
||||
query,
|
||||
/**
|
||||
* Array of Values to Sanitize and Inject
|
||||
*/
|
||||
values) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
if (typeof query == "string") {
|
||||
const res = yield conn.query(query, values);
|
||||
return JSON.parse(JSON.stringify(res));
|
||||
}
|
||||
else if (typeof query == "object") {
|
||||
const resArray = [];
|
||||
for (let i = 0; i < query.length; i++) {
|
||||
const queryObj = query[i];
|
||||
const queryObjRes = yield conn.query(queryObj.query, queryObj.values);
|
||||
resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
|
||||
}
|
||||
return resArray;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
return null;
|
||||
}
|
||||
finally {
|
||||
conn.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
Vendored
+1
-1
@@ -9,7 +9,7 @@ declare function parse(string: string | null | number, reviver?: (this: any, key
|
||||
/**
|
||||
* # EJSON stringify object
|
||||
*/
|
||||
declare function stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string | undefined;
|
||||
declare function stringify(value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number): string | undefined;
|
||||
declare const EJSON: {
|
||||
parse: typeof parse;
|
||||
stringify: typeof stringify;
|
||||
|
||||
Vendored
+1
-1
@@ -22,7 +22,7 @@ function parse(string, reviver) {
|
||||
*/
|
||||
function stringify(value, replacer, space) {
|
||||
try {
|
||||
return JSON.stringify(value, replacer, space);
|
||||
return JSON.stringify(value, replacer || undefined, space);
|
||||
}
|
||||
catch (error) {
|
||||
return undefined;
|
||||
|
||||
+6
-1
@@ -1 +1,6 @@
|
||||
export {};
|
||||
import mysql from "mysql";
|
||||
/**
|
||||
* # End MYSQL Connection
|
||||
*/
|
||||
declare function endConnection(connection: mysql.Connection): void;
|
||||
export default endConnection;
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ function endConnection(connection) {
|
||||
});
|
||||
}
|
||||
}
|
||||
module.exports = endConnection;
|
||||
exports.default = endConnection;
|
||||
|
||||
Reference in New Issue
Block a user