I'm running mariadb locally and want to query for a few rows using the Node driver. I have the following code below that comes straight from the mariadb node docs. I've confirmed my server is up and running and that I can query from the CLI itself.
The weird thing is that the script doesn't fail or throw error. It just gets stuck at the await pool.getConnection()
line. I even waited for like 5 minutes.
My server version is Server version: 10.7.3-MariaDB Homebrew
and I'm using the 3.0.0
package version for Node https://www.npmjs.com/package/mariadb
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: 'localhost',
user: 'node',
password: 'PWD',
connectionLimit: 5,
port: 3306,
database: 'DB',
acquireTimeout: 5000
});
(async () => {
console.log('in iife');
let conn;
try {
console.log('awaiting conn');
//This never gets reached..just gets stuck even after 5s
conn = await pool.getConnection();
console.log(conn);
console.log('awaiting q');
const rows = await conn.query("SELECT * FROM foo where id=1");
console.log(rows);
} catch (err) {
throw err;
} finally {
if (conn) return conn.end();
}
})();
I've actually tried this on two separate devices and have the same exact issue. Any ideas?
CodePudding user response:
It was a red herring. Using dev tools to debug led me to realize there was a mundane runtime error in undeclared var. Red herring was that error was being caught and thrown. But bc this was being called as ad-hoc script, I was never aware of what the error was. Replacing the throw with a console.error led me to see error