CodecademyCommunity / codecademy-discord-bot

Custom moderation bot for the official Codecademy Community Discord server.
https://codecademycommunity.github.io/
MIT License
11 stars 1 forks source link

replace mysql with mysql2 which adds promises #305

Closed mikejoh12 closed 2 years ago

mikejoh12 commented 2 years ago

What issue is this solving?

Closes #304

Description

Replaces mysql with mysql2 library and incorporates connection pooling. The mysql2 library supports using both callbacks and promises from the same connection pool. The mysql2 syntax is mostly compatible with mysql and previous callback code should therefore work while this allows us to incorporate async/await with the db calls going forward.

Any helpful knowledge/context for the reviewer?

The file db.js exports two properties:

module.exports = {
  promisePool,
  getConnection: () => pool,
};

The promisePool object can be used to call the db with promises and async/await. The getConnection function returns a regular callback compatible pool which works with the current code.

We should conduct fairly extensive testing of this PR since it replaces the DB client library and we want to make sure there are no issues with any of the commands.

NPM Library: https://www.npmjs.com/package/mysql2 About promise wrapper: https://github.com/sidorares/node-mysql2#using-promise-wrapper

Please make sure you've attempted to meet the following coding standards