CodeFoodPixels/node-promise-mysql

Get fields of result

Closed this issue · 8 comments

In vanilla node-mysql you can get the fields of a returned query like this:

con.query("...", (err, results, fields) => { console.log(fields) } )

But with node-promise-mysql it seems to have lost that ability:

con.query("...")
    .then((results, fields) => {
        console.log(fields) // undefined
    });

This feels like something that has been overlooked, I was hesitant to post this as an issue as I might just be looking in the wrong place; but I can't figure out how to get the columns.

Thank you in advance!

Is there any way I could access that branch? If it's stable that is. I don't need the majority of the package's functionality.

NB: Jesus that was a quick reply

You can get it here: https://github.com/lukeb-uk/node-promise-mysql/tree/mysql-wrapper

If you pass returnArgumentsArray: true into your connection config object then you'll get an array back as the argument to the promise, so you can do:

con.query("...")
    .then(([results, fields]) => {
        console.log(fields);
    });

Thanks man! Is there any way I could unpack the array before passing it as arguments so I could still use it in the clean results => { ... } way instead of having to do ([results, fields]) => { ... } every time?

Unfortunately not, promises only take one argument.

Ah that's a shame. Seems like a pretty pointless restriction.

It's what's in the spec 🤷‍♂️

If this issue is resolved, please close it

Ah sorry about that, forgot closing issues was a thing. :P