Updates
This commit is contained in:
@@ -2,29 +2,44 @@
|
||||
|
||||
import _ from "lodash";
|
||||
import serverError from "../../backend/serverError";
|
||||
import runQuery from "../../backend/db/runQuery";
|
||||
import { DSQL_TableSchemaType, GetReturn } from "../../../types";
|
||||
import runQuery, { DbContextsArray } from "../../backend/db/runQuery";
|
||||
import {
|
||||
ApiGetQueryObject,
|
||||
DSQL_TableSchemaType,
|
||||
GetReturn,
|
||||
ServerQueryParam,
|
||||
} from "../../../types";
|
||||
import apiGetGrabQueryAndValues from "../../../utils/grab-query-and-values";
|
||||
|
||||
type Param = {
|
||||
query: string;
|
||||
type Param<T extends { [key: string]: any } = { [key: string]: any }> = {
|
||||
query: string | ApiGetQueryObject<T>;
|
||||
queryValues?: (string | number)[];
|
||||
dbFullName: string;
|
||||
tableName?: string;
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
useLocal?: boolean;
|
||||
debug?: boolean;
|
||||
dbContext?: (typeof DbContextsArray)[number];
|
||||
};
|
||||
|
||||
/**
|
||||
* # Get Function FOr API
|
||||
*/
|
||||
export default async function apiGet({
|
||||
export default async function apiGet<
|
||||
T extends { [key: string]: any } = { [key: string]: any }
|
||||
>({
|
||||
query,
|
||||
dbFullName,
|
||||
queryValues,
|
||||
tableName,
|
||||
dbSchema,
|
||||
useLocal,
|
||||
}: Param): Promise<import("../../../types").GetReturn> {
|
||||
debug,
|
||||
dbContext,
|
||||
}: Param<T>): Promise<import("../../../types").GetReturn> {
|
||||
const queryAndValues = apiGetGrabQueryAndValues({
|
||||
query,
|
||||
values: queryValues,
|
||||
});
|
||||
|
||||
if (
|
||||
typeof query == "string" &&
|
||||
query.match(/^alter|^delete|information_schema|databases|^create/i)
|
||||
@@ -37,14 +52,20 @@ export default async function apiGet({
|
||||
try {
|
||||
let { result, error } = await runQuery({
|
||||
dbFullName: dbFullName,
|
||||
query: query,
|
||||
queryValuesArray: queryValues,
|
||||
query: queryAndValues.query,
|
||||
queryValuesArray: queryAndValues.values,
|
||||
readOnly: true,
|
||||
dbSchema,
|
||||
tableName,
|
||||
local: useLocal,
|
||||
dbContext,
|
||||
debug,
|
||||
});
|
||||
|
||||
if (debug && global.DSQL_USE_LOCAL) {
|
||||
console.log("apiGet:result", result);
|
||||
console.log("apiGet:error", error);
|
||||
}
|
||||
|
||||
let tableSchema: DSQL_TableSchemaType | undefined;
|
||||
|
||||
if (dbSchema) {
|
||||
@@ -83,6 +104,10 @@ export default async function apiGet({
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
if (debug && global.DSQL_USE_LOCAL) {
|
||||
console.log("apiGet:error", error.message);
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import _ from "lodash";
|
||||
import serverError from "../../backend/serverError";
|
||||
import runQuery from "../../backend/db/runQuery";
|
||||
import runQuery, { DbContextsArray } from "../../backend/db/runQuery";
|
||||
import { DSQL_DatabaseSchemaType, PostReturn } from "../../../types";
|
||||
|
||||
type Param = {
|
||||
@@ -9,7 +9,7 @@ type Param = {
|
||||
dbFullName: string;
|
||||
tableName?: string;
|
||||
dbSchema?: DSQL_DatabaseSchemaType;
|
||||
useLocal?: boolean;
|
||||
dbContext?: (typeof DbContextsArray)[number];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ export default async function apiPost({
|
||||
queryValues,
|
||||
tableName,
|
||||
dbSchema,
|
||||
useLocal,
|
||||
dbContext,
|
||||
}: Param): Promise<PostReturn> {
|
||||
if (typeof query === "string" && query?.match(/^create |^alter |^drop /i)) {
|
||||
return { success: false, msg: "Wrong Input" };
|
||||
@@ -34,7 +34,6 @@ export default async function apiPost({
|
||||
return { success: false, msg: "Wrong Input" };
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
let results: any;
|
||||
|
||||
/**
|
||||
@@ -49,14 +48,13 @@ export default async function apiPost({
|
||||
dbSchema: dbSchema,
|
||||
queryValuesArray: queryValues,
|
||||
tableName,
|
||||
local: useLocal,
|
||||
dbContext,
|
||||
});
|
||||
|
||||
results = result;
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
/** @type {import("../../../types").DSQL_TableSchemaType | undefined} */
|
||||
let tableSchema:
|
||||
| import("../../../types").DSQL_TableSchemaType
|
||||
| undefined;
|
||||
|
||||
Reference in New Issue
Block a user