Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get fields of result #94

Closed
charlielidbury opened this issue Jul 5, 2018 · 8 comments
Closed

Get fields of result #94

charlielidbury opened this issue Jul 5, 2018 · 8 comments

Comments

@charlielidbury
Copy link

charlielidbury commented Jul 5, 2018

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
Copy link
Owner

CodeFoodPixels commented Jul 5, 2018 via email

@charlielidbury
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

Unfortunately not, promises only take one argument.

@charlielidbury
Copy link
Author

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

@CodeFoodPixels
Copy link
Owner

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

If this issue is resolved, please close it

@charlielidbury
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants