diff --git a/src/config.js b/src/config.js deleted file mode 100644 index 26a5039..0000000 --- a/src/config.js +++ /dev/null @@ -1,21 +0,0 @@ -const slowQueryWarning = GetConvarInt('mysql_slow_query_warning', 150); -const debug = GetConvar('mysql_debug', 'false') === 'true'; - -const isolationLevel = (() => { - switch (GetConvarInt('mysql_transaction_isolation_level', 2)) { - case 1: - return 'SET TRANSACTION ISOLATION LEVEL REPEATABLE READ'; - case 2: - return 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED'; - case 3: - return 'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED'; - case 4: - return 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'; - default: - return 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED'; - } -})(); - -const resourceName = GetCurrentResourceName(); - -export { slowQueryWarning, debug, isolationLevel, resourceName }; diff --git a/src/server/config.js b/src/server/config.js new file mode 100644 index 0000000..b8891dd --- /dev/null +++ b/src/server/config.js @@ -0,0 +1,39 @@ +export const resourceName = GetCurrentResourceName(); + +export const mysql_debug = GetConvar('mysql_debug', 'false') === 'true'; +export const mysql_slow_query_warning = GetConvarInt('mysql_slow_query_warning', 200); +export const mysql_connection_string = GetConvar('mysql_connection_string', ''); + +export const mysql_transaction_isolation_level = (() => { + const query = 'SET TRANSACTION ISOLATION LEVEL'; + switch (GetConvarInt('mysql_transaction_isolation_level', 2)) { + case 1: + return `${query} REPEATABLE READ`; + case 2: + return `${query} READ COMMITTED`; + case 3: + return `${query} READ UNCOMMITTED`; + case 4: + return `${query} SERIALIZABLE`; + default: + return `${query} READ COMMITTED`; + } +})(); + +export const typeCast = (field, next) => { + switch (field.type) { + case 'DATETIME': + case 'DATETIME2': + case 'TIMESTAMP': + case 'TIMESTAMP2': + case 'NEWDATE': + case 'DATE': + return field.type === 'DATE' ? new Date(field.string() + ' 00:00:00').getTime() : new Date(field.string()).getTime(); + case 'TINY': + return field.length === 1 ? field.string() === '1' : next(); + case 'BIT': + return field.buffer()[0] === 1; + default: + return next(); + } +};