Skip to content

Commit

Permalink
refactor(config): moved typeCast function into config
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Dec 23, 2021
1 parent 35f198f commit f5e25e3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
21 changes: 0 additions & 21 deletions src/config.js

This file was deleted.

39 changes: 39 additions & 0 deletions src/server/config.js
Original file line number Diff line number Diff line change
@@ -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();
}
};

0 comments on commit f5e25e3

Please sign in to comment.