2023-07-07 14:43:33 +00:00
|
|
|
/**
|
|
|
|
* Imports: Handle imports
|
|
|
|
*/
|
2023-07-08 06:15:25 +00:00
|
|
|
const dsqlDbHandler = require("../utils/dsqlDbHandler");
|
2023-07-07 14:43:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete DB Entry Function
|
|
|
|
* ==============================================================================
|
|
|
|
* @description Description
|
2023-07-07 14:52:24 +00:00
|
|
|
* @async
|
2023-07-07 14:43:33 +00:00
|
|
|
*
|
|
|
|
* @param {object} params - An object containing the function parameters.
|
|
|
|
* @param {string} params.dbFullName - Database full name
|
|
|
|
* @param {string} params.tableName - Table name
|
|
|
|
* @param {DSQL_TableSchemaType?} params.tableSchema - Table schema
|
|
|
|
* @param {string} params.identifierColumnName - Update row identifier column name
|
|
|
|
* @param {string|number} params.identifierValue - Update row identifier column value
|
|
|
|
* @param {boolean?} params.update - Update this row if it exists
|
|
|
|
* @param {string?} params.dbHost - Database host
|
|
|
|
* @param {string?} params.dbPassword - Database password
|
|
|
|
* @param {string?} params.dbUsername - Database username
|
|
|
|
* @param {string?} params.encryptionKey - Encryption key
|
|
|
|
* @param {string?} params.encryptionSalt - Encryption salt
|
|
|
|
*
|
2023-07-07 14:52:24 +00:00
|
|
|
* @returns {Promise<object|null>}
|
2023-07-07 14:43:33 +00:00
|
|
|
*/
|
2023-07-07 19:13:13 +00:00
|
|
|
async function deleteDb({ dbFullName, tableName, identifierColumnName, identifierValue, dbHost, dbPassword, dbUsername, encryptionKey, encryptionSalt }) {
|
2023-07-07 14:43:33 +00:00
|
|
|
try {
|
|
|
|
/**
|
|
|
|
* Check if data is valid
|
|
|
|
*/
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execution
|
|
|
|
*
|
|
|
|
* @description
|
|
|
|
*/
|
|
|
|
const query = `DELETE FROM ${tableName} WHERE \`${identifierColumnName}\`=?`;
|
|
|
|
|
2023-07-08 06:15:25 +00:00
|
|
|
const deletedEntry = await dsqlDbHandler({
|
2023-07-07 14:43:33 +00:00
|
|
|
queryString: query,
|
|
|
|
database: dbFullName,
|
|
|
|
queryValuesArray: [identifierValue],
|
|
|
|
dbHost,
|
|
|
|
dbPassword,
|
|
|
|
dbUsername,
|
|
|
|
encryptionKey,
|
|
|
|
encryptionSalt,
|
|
|
|
});
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return statement
|
|
|
|
*/
|
|
|
|
return deletedEntry;
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
} catch (error) {
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2023-07-07 19:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
module.exports = deleteDb;
|