Updates
This commit is contained in:
+2
-1
@@ -5,9 +5,10 @@ type Param = {
|
||||
tableName?: string;
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
useLocal?: boolean;
|
||||
debug?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Get Function FOr API
|
||||
*/
|
||||
export default function apiGet({ query, dbFullName, queryValues, tableName, dbSchema, useLocal, }: Param): Promise<import("../../../types").GetReturn>;
|
||||
export default function apiGet({ query, dbFullName, queryValues, tableName, dbSchema, useLocal, debug, }: Param): Promise<import("../../../types").GetReturn>;
|
||||
export {};
|
||||
|
||||
+8
-1
@@ -21,7 +21,7 @@ const runQuery_1 = __importDefault(require("../../backend/db/runQuery"));
|
||||
* # Get Function FOr API
|
||||
*/
|
||||
function apiGet(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ query, dbFullName, queryValues, tableName, dbSchema, useLocal, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ query, dbFullName, queryValues, tableName, dbSchema, useLocal, debug, }) {
|
||||
if (typeof query == "string" &&
|
||||
query.match(/^alter|^delete|information_schema|databases|^create/i)) {
|
||||
return { success: false, msg: "Wrong Input." };
|
||||
@@ -37,6 +37,10 @@ function apiGet(_a) {
|
||||
tableName,
|
||||
local: useLocal,
|
||||
});
|
||||
if (debug) {
|
||||
console.log("apiGet:result", result);
|
||||
console.log("apiGet:error", error);
|
||||
}
|
||||
let tableSchema;
|
||||
if (dbSchema) {
|
||||
const targetTable = dbSchema.tables.find((table) => table.tableName === tableName);
|
||||
@@ -69,6 +73,9 @@ function apiGet(_a) {
|
||||
component: "/api/query/get/lines-85-94",
|
||||
message: error.message,
|
||||
});
|
||||
if (debug) {
|
||||
console.log("apiGet:error", error.message);
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
|
||||
+2
-1
@@ -3,6 +3,7 @@ type Param = {
|
||||
query: string | any;
|
||||
readOnly?: boolean;
|
||||
local?: boolean;
|
||||
debug?: boolean;
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
queryValuesArray?: (string | number)[];
|
||||
tableName?: string;
|
||||
@@ -10,5 +11,5 @@ type Param = {
|
||||
/**
|
||||
* # Run DSQL users queries
|
||||
*/
|
||||
export default function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, local, }: Param): Promise<any>;
|
||||
export default function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, local, debug, }: Param): Promise<any>;
|
||||
export {};
|
||||
|
||||
+8
-2
@@ -24,7 +24,7 @@ const trim_sql_1 = __importDefault(require("../../../utils/trim-sql"));
|
||||
* # Run DSQL users queries
|
||||
*/
|
||||
function runQuery(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, local, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, local, debug, }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
@@ -58,6 +58,9 @@ function runQuery(_a) {
|
||||
try {
|
||||
if (typeof query === "string") {
|
||||
const formattedQuery = (0, trim_sql_1.default)(query);
|
||||
if (debug) {
|
||||
console.log("runQuery:formattedQuery", formattedQuery);
|
||||
}
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
@@ -140,11 +143,14 @@ function runQuery(_a) {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
catch (error) {
|
||||
(0, serverError_1.default)({
|
||||
component: "functions/backend/runQuery",
|
||||
message: error.message,
|
||||
});
|
||||
if (debug) {
|
||||
console.log("runQuery:error", error.message);
|
||||
}
|
||||
result = null;
|
||||
error = error.message;
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -167,6 +167,7 @@ export interface GetReqQueryObject {
|
||||
query: string;
|
||||
queryValues?: string;
|
||||
tableName?: string;
|
||||
debug?: boolean;
|
||||
}
|
||||
export type DATASQUIREL_LoggedInUser = {
|
||||
id: number;
|
||||
|
||||
Vendored
+2
-1
@@ -7,9 +7,10 @@ type Param = {
|
||||
tableName?: string;
|
||||
useLocal?: boolean;
|
||||
user_id?: string | number;
|
||||
debug?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Make a get request to Datasquirel API
|
||||
*/
|
||||
export default function get({ key, db, query, queryValues, tableName, useLocal, user_id, }: Param): Promise<GetReturn>;
|
||||
export default function get({ key, db, query, queryValues, tableName, useLocal, user_id, debug, }: Param): Promise<GetReturn>;
|
||||
export {};
|
||||
|
||||
Vendored
+15
-2
@@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
// @ts-check
|
||||
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) {
|
||||
@@ -23,7 +22,7 @@ const serialize_query_1 = __importDefault(require("../package-shared/utils/seria
|
||||
* # Make a get request to Datasquirel API
|
||||
*/
|
||||
function get(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, db, query, queryValues, tableName, useLocal, user_id, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, db, query, queryValues, tableName, useLocal, user_id, debug, }) {
|
||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
/**
|
||||
@@ -44,6 +43,9 @@ function get(_a) {
|
||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
||||
}
|
||||
catch (error) { }
|
||||
if (debug) {
|
||||
console.log("apiGet:Running Locally ...");
|
||||
}
|
||||
return yield (0, get_1.default)({
|
||||
dbFullName: DSQL_DB_NAME,
|
||||
query,
|
||||
@@ -51,6 +53,7 @@ function get(_a) {
|
||||
tableName,
|
||||
dbSchema,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
}
|
||||
/**
|
||||
@@ -66,9 +69,19 @@ function get(_a) {
|
||||
? JSON.stringify(queryValues)
|
||||
: undefined,
|
||||
tableName,
|
||||
debug,
|
||||
};
|
||||
if (debug) {
|
||||
console.log("apiGet:queryObject", queryObject);
|
||||
}
|
||||
const queryString = (0, serialize_query_1.default)(Object.assign({}, queryObject));
|
||||
if (debug) {
|
||||
console.log("apiGet:queryString", queryString);
|
||||
}
|
||||
let path = `/api/query/${user_id || grabedHostNames.user_id}/get${queryString}`;
|
||||
if (debug) {
|
||||
console.log("apiGet:path", path);
|
||||
}
|
||||
const requestObject = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user