This commit is contained in:
Benjamin Toby
2025-01-15 22:59:16 +01:00
parent a2feec6f5b
commit b18ec506b3
6 changed files with 89 additions and 23 deletions
+44 -13
View File
@@ -4,12 +4,23 @@ import fs from "fs";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiGet from "../package-shared/functions/api/query/get";
import serializeQuery from "../package-shared/utils/serialize-query";
import { GetReturn } from "../package-shared/types";
import {
GetReqQueryObject,
GetReturn,
ServerQueryParam,
} from "../package-shared/types";
import sqlGenerator from "../package-shared/functions/dsql/sql/sql-generator";
export type ApiGetQueryObject = {
query: ServerQueryParam;
table: string;
dbFullName?: string;
};
type Param = {
key?: string;
db?: string;
query: string;
query: string | ApiGetQueryObject;
queryValues?: string[];
tableName?: string;
useLocal?: boolean;
@@ -17,6 +28,8 @@ type Param = {
debug?: boolean;
};
export type ApiGetParams = Param;
/**
* # Make a get request to Datasquirel API
*/
@@ -82,18 +95,36 @@ export default async function get({
* @description make a request to datasquirel.com
*/
const httpResponse = await new Promise((resolve, reject) => {
const queryObject: import("../package-shared/types").GetReqQueryObject =
{
db: process.env.DSQL_API_DB_NAME || String(db),
query: String(
query.replace(/\n|\r|\n\r/g, "").replace(/ {2,}/g, " ")
),
queryValues: queryValues
? JSON.stringify(queryValues)
const queryGenObject =
typeof query == "string"
? undefined
: sqlGenerator({
tableName: query.table,
genObject: query.query,
dbFullName: query.dbFullName || "__db",
});
const queryObject: GetReqQueryObject = {
db: process.env.DSQL_API_DB_NAME || String(db),
query:
typeof query == "string"
? String(
query
.replace(/\n|\r|\n\r/g, "")
.replace(/ {2,}/g, " ")
)
: queryGenObject?.string || "",
queryValues:
typeof query == "string"
? queryValues
? JSON.stringify(queryValues)
: undefined
: queryGenObject?.values
? JSON.stringify(queryGenObject.values)
: undefined,
tableName,
debug,
};
tableName,
debug,
};
if (debug) {
console.log("apiGet:queryObject", queryObject);