Updates
This commit is contained in:
parent
785b15aad5
commit
e13a14ab5c
@ -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 {};
|
||||
|
@ -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,
|
||||
|
@ -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 {};
|
||||
|
@ -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;
|
||||
}
|
||||
|
1
dist/package-shared/types/index.d.ts
vendored
1
dist/package-shared/types/index.d.ts
vendored
@ -167,6 +167,7 @@ export interface GetReqQueryObject {
|
||||
query: string;
|
||||
queryValues?: string;
|
||||
tableName?: string;
|
||||
debug?: boolean;
|
||||
}
|
||||
export type DATASQUIREL_LoggedInUser = {
|
||||
id: number;
|
||||
|
3
dist/utils/get.d.ts
vendored
3
dist/utils/get.d.ts
vendored
@ -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 {};
|
||||
|
17
dist/utils/get.js
vendored
17
dist/utils/get.js
vendored
@ -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: {
|
||||
|
@ -12,6 +12,7 @@ type Param = {
|
||||
tableName?: string;
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
useLocal?: boolean;
|
||||
debug?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -24,6 +25,7 @@ export default async function apiGet({
|
||||
tableName,
|
||||
dbSchema,
|
||||
useLocal,
|
||||
debug,
|
||||
}: Param): Promise<import("../../../types").GetReturn> {
|
||||
if (
|
||||
typeof query == "string" &&
|
||||
@ -45,6 +47,11 @@ export default async function apiGet({
|
||||
local: useLocal,
|
||||
});
|
||||
|
||||
if (debug) {
|
||||
console.log("apiGet:result", result);
|
||||
console.log("apiGet:error", error);
|
||||
}
|
||||
|
||||
let tableSchema: DSQL_TableSchemaType | undefined;
|
||||
|
||||
if (dbSchema) {
|
||||
@ -83,6 +90,10 @@ export default async function apiGet({
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
if (debug) {
|
||||
console.log("apiGet:error", error.message);
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
|
@ -12,6 +12,7 @@ type Param = {
|
||||
query: string | any;
|
||||
readOnly?: boolean;
|
||||
local?: boolean;
|
||||
debug?: boolean;
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
queryValuesArray?: (string | number)[];
|
||||
tableName?: string;
|
||||
@ -28,6 +29,7 @@ export default async function runQuery({
|
||||
queryValuesArray,
|
||||
tableName,
|
||||
local,
|
||||
debug,
|
||||
}: Param): Promise<any> {
|
||||
/**
|
||||
* Declare variables
|
||||
@ -66,6 +68,10 @@ export default async function runQuery({
|
||||
if (typeof query === "string") {
|
||||
const formattedQuery = trimSql(query);
|
||||
|
||||
if (debug) {
|
||||
console.log("runQuery:formattedQuery", formattedQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
@ -167,11 +173,16 @@ export default async function runQuery({
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
} catch (error: any) {
|
||||
serverError({
|
||||
component: "functions/backend/runQuery",
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
if (debug) {
|
||||
console.log("runQuery:error", error.message);
|
||||
}
|
||||
|
||||
result = null;
|
||||
error = error.message;
|
||||
}
|
||||
|
@ -185,6 +185,7 @@ export interface GetReqQueryObject {
|
||||
query: string;
|
||||
queryValues?: string;
|
||||
tableName?: string;
|
||||
debug?: boolean;
|
||||
}
|
||||
|
||||
export type DATASQUIREL_LoggedInUser = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "3.6.3",
|
||||
"version": "3.6.4",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
22
utils/get.ts
22
utils/get.ts
@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import https from "node:https";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
@ -16,6 +14,7 @@ type Param = {
|
||||
tableName?: string;
|
||||
useLocal?: boolean;
|
||||
user_id?: string | number;
|
||||
debug?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -29,6 +28,7 @@ export default async function get({
|
||||
tableName,
|
||||
useLocal,
|
||||
user_id,
|
||||
debug,
|
||||
}: Param): Promise<GetReturn> {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@ -61,6 +61,10 @@ export default async function get({
|
||||
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
|
||||
} catch (error) {}
|
||||
|
||||
if (debug) {
|
||||
console.log("apiGet:Running Locally ...");
|
||||
}
|
||||
|
||||
return await apiGet({
|
||||
dbFullName: DSQL_DB_NAME,
|
||||
query,
|
||||
@ -68,6 +72,7 @@ export default async function get({
|
||||
tableName,
|
||||
dbSchema,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
}
|
||||
|
||||
@ -87,14 +92,27 @@ export default async function get({
|
||||
? JSON.stringify(queryValues)
|
||||
: undefined,
|
||||
tableName,
|
||||
debug,
|
||||
};
|
||||
|
||||
if (debug) {
|
||||
console.log("apiGet:queryObject", queryObject);
|
||||
}
|
||||
|
||||
const queryString = serializeQuery({ ...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: https.RequestOptions = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
|
Loading…
Reference in New Issue
Block a user