0

I am trying to output a list of all the items from a MYSQL table to the console while using Node JS however when trying to use the code it gives me the error thata Callback function is not available with promise clients (the database connection is a promise as it is SSH tunnelled back to our university) any help with this would be really useful!!

 var database = require('./dbConfig');
database.then((con) => {
    con.query('SELECT * FROM Pupils', (err, rows) => {
        console.log(rows)
    })
}) 
6
  • Try con.query('SELECT * FROM Pupils').then(result => console.log(result)) Commented Jan 14, 2021 at 15:37
  • Thank you!! This Worked but now it outputs a Column Definition in the console for all columns in the table, is there a way to stop this? Commented Jan 14, 2021 at 15:45
  • what is the db library you are using? sequelize? Commented Jan 14, 2021 at 15:52
  • con.query('SELECT * FROM Pupils').then(([result]) => console.log(result)) Commented Jan 14, 2021 at 16:30
  • @germanio I guess it's mysql2 Commented Jan 14, 2021 at 16:35

1 Answer 1

1

I'd do:

await database.promise().query("SELECT * FROM Pupils")
    .then( ([rows,fields]) => {
        //return your results
    })
    .catch(console.log)

as a starting point for your code. Then you can tweak it to your needs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.