updates
This commit is contained in:
parent
43a6271eed
commit
57ed81ed01
76
engine/db/query.js
Normal file
76
engine/db/query.js
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Imports: Handle imports
|
||||
*/
|
||||
|
||||
const handler = require("../utils/handler");
|
||||
|
||||
/**
|
||||
* RAW Query DB Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {string} params.dbFullName - Database full name
|
||||
* @param {string?} params.dbHost - Database host
|
||||
* @param {string?} params.dbPassword - Database password
|
||||
* @param {string?} params.dbUsername - Database username
|
||||
* @param {string?} params.query - Query string
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
module.exports = async function query({ dbFullName, dbHost, dbPassword, dbUsername, query }) {
|
||||
/**
|
||||
* Initialize variables
|
||||
*/
|
||||
const mysql = require("serverless-mysql")({
|
||||
config: {
|
||||
host: dbHost,
|
||||
user: dbUsername,
|
||||
password: dbPassword,
|
||||
database: dbFullName.toString().replace(/[^a-z0-9\_\-]/g, ""),
|
||||
charset: "utf8mb4",
|
||||
},
|
||||
});
|
||||
|
||||
let results;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
try {
|
||||
/**
|
||||
* Run Query
|
||||
*/
|
||||
results = await mysql.query(query);
|
||||
|
||||
/**
|
||||
* Clean up
|
||||
*/
|
||||
await mysql.end();
|
||||
} catch (error) {
|
||||
/**
|
||||
* Handle error and clean up
|
||||
*/
|
||||
console.log("\x1b[31mDSQL Database Handler ERROR\x1b[0m =>", database, error.message);
|
||||
|
||||
/**
|
||||
* Clean up
|
||||
*/
|
||||
await mysql.end();
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
if (results) {
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
} else {
|
||||
console.log("\x1b[31mDSQL RAW Database Handler No results returned\x1b[0m =>", results);
|
||||
return null;
|
||||
}
|
||||
};
|
@ -3,6 +3,7 @@
|
||||
* ===================================
|
||||
*/
|
||||
const add = require("./db/add");
|
||||
const query = require("./db/query");
|
||||
const update = require("./db/update");
|
||||
|
||||
////////////////////////////////////////
|
||||
@ -17,6 +18,7 @@ const db = {
|
||||
add: add,
|
||||
update: update,
|
||||
delete: update,
|
||||
query: query,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "datasquirel",
|
||||
"version": "1.1.61",
|
||||
"version": "1.1.62",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user