Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB: fix DB connection and query format #413

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
}
};
Loading