This commit is contained in:
Tben
2023-08-12 16:46:00 +01:00
parent da559d13ff
commit cb195616b3
27 changed files with 727 additions and 564 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ const localGet = require("../engine/query/get");
/**
* @typedef {Object} GetReturn
* @property {boolean} success - Did the function run successfully?
* @property {(Object[]|string|null|object)} [payload] - GET request results
* @property {*} [payload] - GET request results
* @property {string} [msg] - Message
* @property {string} [error] - Error Message
*/
+31
View File
@@ -4,6 +4,9 @@
* Imports
*/
const https = require("https");
const path = require("path");
const fs = require("fs");
const localPost = require("../engine/query/post");
/** ****************************************************************************** */
/** ****************************************************************************** */
@@ -49,6 +52,34 @@ const https = require("https");
* @returns { Promise<PostReturn> } - Return Object
*/
async function post({ key, query, queryValues, database, tableName }) {
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_HOST, DSQL_USER, DSQL_PASS, DSQL_DB_NAME, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC } = process.env;
if (DSQL_HOST?.match(/./) && DSQL_USER?.match(/./) && DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./)) {
/** @type {import("../types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
} catch (error) {}
console.log("Reading from local database ...");
return await localPost({
dbSchema: dbSchema,
options: {
query: query,
queryValues: queryValues,
tableName: tableName,
},
});
}
/**
* Make https request
*