Skip to content

Commit

Permalink
Merge pull request #413 from iFixit/mysql2-bugfix
Browse files Browse the repository at this point in the history
DB: fix DB connection and query format
  • Loading branch information
danielbeardsley authored Sep 3, 2024
2 parents 9449c42 + b4f26d8 commit d1628b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/db-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ var dbManager = (module.exports = {
*/
deleteLabels: function deleteLabels(repo, number) {
debug("Calling deleteLabels for pull #%s in repo %s", number, repo);
var q_delete = "DELETE FROM pull_labels WHERE number = ? " + "AND repo = ?";
var q_delete = "DELETE FROM pull_labels WHERE number = ? AND repo = ?";
return db.query(q_delete, [number, repo]);
},

Expand Down
23 changes: 17 additions & 6 deletions lib/db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
var mysql = require("mysql2"),
config = require("./config-loader"),
Promise = require("bluebird");
var mysql = require("mysql2/promise"),
config = require("./config-loader");

// OMG, this took forever to figure out
// Add support for understanding utf8mb3 charset to the mysql2 library
// https://github.com/sidorares/node-mysql2/issues/1398
// We don't have any utf8mb3 columns, but if you run a query that generates
// no result (DELETE, REPLACE, ...) it will return metadata indicating that the
// empty result is in the "servers" charset, which is utf8mb3 (still)
var EncodingToCharset = require("../node_modules/mysql2/lib/constants/encoding_charset");
EncodingToCharset.utf8mb3 = 192;

const pool = mysql.createPool({
host: config.mysql.host,
Expand All @@ -10,6 +18,9 @@ const pool = mysql.createPool({
charset: "utf8mb4",
});

pool.query = Promise.promisify(pool.query);

module.exports = pool;
module.exports = {
query: function(query, params) {
return pool.query(query, params)
.then((result) => result[0]); // [rows, fields]
}
};

0 comments on commit d1628b4

Please sign in to comment.