I want to know if node.js mysql gives a query success indicator. I want to do a CREATE DATABASE IF NOT EXIST query, and if the database did not exist and was created properly, execute a bunch of files (that create my tables). The files that create the tables are already coded and I tested them. I just do not understand (due to really meh documentaton) how to do "if database was successfully created do x else do y" portion of the logic.
const config = require("./database");
var connection = config.db.get;
connection.query(
"CREATE DATABASE IF NOT EXISTS " . config.database,
function (err, result, fields) {
if (err) throw err;
console.log("result: " + result);
if(!success) {
//do nothing, we assume the database adn tables are already setup.
}
else {
require("./models/company");
require("./models/locations");
}
});
How can I create a boolean variable based on if the query was successful or not, assuming that it would be false if the database exists before running the CREATE DATABASE query.