CodeFoodPixels / node-promise-mysql

A wrapper for mysqljs/mysql that wraps function calls with Bluebird promises.
MIT License
338 stars 64 forks source link

Get fields of result #94

Closed charlielidbury closed 6 years ago

charlielidbury commented 6 years ago

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!

CodeFoodPixels commented 6 years ago

There's a branch that I'm working on that brings this back.

On Thu, 5 Jul 2018, 12:23 Charlie, notifications@github.com wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lukeb-uk/node-promise-mysql/issues/94, or mute the thread https://github.com/notifications/unsubscribe-auth/AEjy1Fhq_dXdcr2EE5X7AvYq6Pp5dz4wks5uDfcygaJpZM4VDtTh .

charlielidbury commented 6 years ago

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

CodeFoodPixels commented 6 years ago

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);
    });
charlielidbury commented 6 years ago

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?

CodeFoodPixels commented 6 years ago

Unfortunately not, promises only take one argument.

charlielidbury commented 6 years ago

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

CodeFoodPixels commented 6 years ago

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

If this issue is resolved, please close it

charlielidbury commented 6 years ago

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