Use new divider style
This commit is contained in:
@@ -8,11 +8,11 @@
|
||||
// TYPE: Server (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
let persistentDatabaseConnection = null;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function initDatabaseScript() {
|
||||
logToConsole(LOG_INFO, "[Asshat.Database]: Initializing database script ...");
|
||||
@@ -20,7 +20,7 @@ function initDatabaseScript() {
|
||||
logToConsole(LOG_INFO, "[Asshat.Database]: Database script initialized successfully!");
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function connectToDatabase() {
|
||||
if(persistentDatabaseConnection == null) {
|
||||
@@ -40,27 +40,28 @@ function connectToDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function disconnectFromDatabase(dbConnection) {
|
||||
if(!databaseConfig.usePersistentConnection) {
|
||||
try {
|
||||
dbConnection.close();
|
||||
logToConsole(LOG_DEBUG, `Database connection closed successfully`);
|
||||
logToConsole(LOG_DEBUG, `[Asshat.Database] Database connection closed successfully`);
|
||||
} catch(error) {
|
||||
logToConsole(LOG_ERROR, `Database connection could not be closed! (Error: ${error})`);
|
||||
logToConsole(LOG_ERROR, `[Asshat.Database] Database connection could not be closed! (Error: ${error})`);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function queryDatabase(dbConnection, queryString) {
|
||||
logToConsole(LOG_DEBUG, `[Asshat.Database] Query string: ${queryString}`);
|
||||
return dbConnection.query(queryString);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function escapeDatabaseString(dbConnection, unsafeString = "") {
|
||||
if(!dbConnection) {
|
||||
@@ -73,25 +74,25 @@ function escapeDatabaseString(dbConnection, unsafeString = "") {
|
||||
return unsafeString;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function getDatabaseInsertId(dbConnection) {
|
||||
return dbConnection.insertId;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function getQueryNumRows(dbQuery) {
|
||||
return dbQuery.numRows;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function getDatabaseError(dbConnection) {
|
||||
return dbConnection.error;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function freeDatabaseQuery(dbQuery) {
|
||||
if(dbQuery != null) {
|
||||
@@ -100,31 +101,31 @@ function freeDatabaseQuery(dbQuery) {
|
||||
return;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function fetchQueryAssoc(dbQuery) {
|
||||
return dbQuery.fetchAssoc();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function quickDatabaseQuery(queryString) {
|
||||
let dbConnection = connectToDatabase();
|
||||
let insertId = 0;
|
||||
if(dbConnection) {
|
||||
logToConsole(LOG_DEBUG, queryString);
|
||||
logToConsole(LOG_DEBUG, `[Asshat.Database] Query string: ${queryString}`);
|
||||
let dbQuery = queryDatabase(dbConnection, queryString);
|
||||
if(getDatabaseInsertId(dbConnection)) {
|
||||
insertId = getDatabaseInsertId(dbConnection);
|
||||
logToConsole(LOG_DEBUG, `Query returned insert id ${insertId}`);
|
||||
logToConsole(LOG_DEBUG, `[Asshat.Database] Query returned insert id ${insertId}`);
|
||||
}
|
||||
|
||||
if(dbQuery) {
|
||||
try {
|
||||
freeDatabaseQuery(dbQuery);
|
||||
logToConsole(LOG_DEBUG, `Query result free'd successfully`);
|
||||
logToConsole(LOG_DEBUG, `[Asshat.Database] Query result free'd successfully`);
|
||||
} catch(error) {
|
||||
logToConsole(LOG_ERROR, `Query result could not be free'd! (Error: ${error})`);
|
||||
logToConsole(LOG_ERROR, `[Asshat.Database] Query result could not be free'd! (Error: ${error})`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ function quickDatabaseQuery(queryString) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function executeDatabaseQueryCommand(command, params, client) {
|
||||
if(areParamsEmpty(params)) {
|
||||
@@ -170,20 +171,20 @@ function executeDatabaseQueryCommand(command, params, client) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function setConstantsAsGlobalVariablesInDatabase() {
|
||||
let dbConnection = connectToDatabase();
|
||||
let entries = Object.entries(global);
|
||||
for(let i in entries) {
|
||||
logToConsole(LOG_DEBUG, `Checking entry ${i} (${entries[i]})`);
|
||||
logToConsole(LOG_DEBUG, `[Asshat.Database] Checking entry ${i} (${entries[i]})`);
|
||||
if(toString(i).slice(0, 3).indexOf("AG_") != -1) {
|
||||
logToConsole(LOG_DEBUG, `Adding ${i} (${entries[i]}) to database global variables`);
|
||||
logToConsole(LOG_DEBUG, `[Asshat.Database] Adding ${i} (${entries[i]}) to database global variables`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ===========================================================================
|
||||
|
||||
function loadDatabaseConfiguration() {
|
||||
let databaseConfigFile = loadTextFile("config/database.json");
|
||||
|
||||
Reference in New Issue
Block a user