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

rowCount unavailable after UPDATE / INSERT / DELETE #17

Closed
vitaly-t opened this issue Apr 19, 2015 · 17 comments
Closed

rowCount unavailable after UPDATE / INSERT / DELETE #17

vitaly-t opened this issue Apr 19, 2015 · 17 comments

Comments

@vitaly-t
Copy link
Owner

Created on behalf of @mdvorak, after his merge request.

Method query provides no access to rowCount after successful execution of INSERT/UPDATE/DELETE.

@mdvorak
Copy link

mdvorak commented Apr 19, 2015

MyBatis solves this by having methods like selectOne, selectList, selectMap for data retrieval
and delete, update, insert for modifications. It is explicit, but i thing actually method update with rowCount as result would suffice.

My original solution provides you access to full result object, which allows future users to get any possible future properties available there :) Also might allow easier transition from pure pg/other libraries to this one. Therefore, I would still include it.

@vitaly-t
Copy link
Owner Author

I'd like to see that no other fix is possible in the meantime, before opting for a breaking change. I'll try to come up with some ideas....

@mdvorak
Copy link

mdvorak commented Apr 19, 2015

My PR wasn't breaking, it just added new queryResult. But having .update(...).then(function(rowCount) {}); would serve as well. I can't think of case where you would need both data and rowCount.
If you don't want to have generic passthru method, this is my suggestion.

@vitaly-t
Copy link
Owner Author

Method query already has all the information, it just needs to return the extra result. This can be achieved either through an extra option added to the method or another method name. I would't call it anything specific to update/insert/delete, because it should remain generic.

Something like queryCount?

@vitaly-t vitaly-t changed the title rowCount unavailable after UPDATE / INSERT rowCount unavailable after UPDATE / INSERT / DELETE Apr 19, 2015
@vitaly-t
Copy link
Owner Author

You know, I think I have a better idea...

How about, we add method called something like raw and have it resolve with the entire result object as returned from pg? This would be your passthrough method.

The more I think about it, the more I like it, except perhaps for the method name :)

Thinking of a better name, please throw in some of your own ;)

  • direct
  • getAll
  • get
  • rawData
  • rawQuery
  • result
  • getResult

Right now I think the one that best fits the architecture logic is rawQuery.

@vitaly-t
Copy link
Owner Author

I can't think of case where you would need both data and rowCount.

Well, if you execute something like this:

UPDATE users SET login = 'myName' RETURNING id

I just tested it, and I got both. Although now the row.length is the same as rowCount, so probably not so important... I'm just not quite sure...

@mdvorak
Copy link

mdvorak commented Apr 19, 2015

Well, that still produces rows array, therefore you have its length property.
But I was also originally thinking about raw as queryResult, so rawQuery or queryRaw sounds fine to me. queryRaw fits me better, since you are executing query and consuming raw result. While rawQuery would make me think i'm bypassing pg-promise query formatting (pgFormatting=true).

@vitaly-t
Copy link
Owner Author

Very good. I'm adding support for queryRaw right now ;) It makes perfect sense. Cheers!

@vitaly-t
Copy link
Owner Author

I have implemented, tested, and checked in the changes. You can get them from the current index.js in the master branch.

New method queryRaw(query, values) will resolve with the PG's result.

There will be some documentation, and perhaps extra tests added before I release it as 1.0.3 (it's not a breaking change).

@mdvorak
Copy link

mdvorak commented Apr 19, 2015

Thats great news, thanks!

@vitaly-t
Copy link
Owner Author

Version 1.0.3 has been released. There were some changes in the source after all, to fix an issue found after adding a few good tests, which is always nice.

I will be adding an example to the Learn by Example tutorial shortly, but in the meantime the issue is closed.

Thank you for your help! 👍

@vitaly-t
Copy link
Owner Author

Raw Result example has been added to the Learn by Example tutorial ;)

@vitaly-t
Copy link
Owner Author

@mdvorak, Unrelated to this, but if you liked this library, I really appreciate if you can give me a feedback on this small addition: pg-monitor

@vitaly-t
Copy link
Owner Author

vitaly-t commented Jul 4, 2015

@mdvorak reflecting on some of the passed changes, added method result in Release 1.7.4 as another alias to queryRaw, because this is what it should have been called.

@miraage
Copy link

miraage commented Dec 10, 2015

https://github.com/vitaly-t/pg-promise/wiki/Learn-by-Example#affected-rows
broken. could you please update wiki?

@vitaly-t
Copy link
Owner Author

Where is this link declared?

On 10 December 2015 at 16:13, Mikhail Osher notifications@github.com
wrote:

https://github.com/vitaly-t/pg-promise/wiki/Learn-by-Example#affected-rows
broken. could you please update wiki?


Reply to this email directly or view it on GitHub
#17 (comment).

@vitaly-t
Copy link
Owner Author

@miraage The link has been updated: Raw Result

Cheers!

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

No branches or pull requests

3 participants