postgres-nio icon indicating copy to clipboard operation
postgres-nio copied to clipboard

Expose query `metadata`

Open MahdiBM opened this issue 1 year ago β€’ 11 comments

Currently the functions that return PostgresRowSequence have no way of reporting back the metadata of the query. This PR exposes the metadata.

Checklist

  • [x] Add PostgresConnection tests for the new query and execute funcs
  • [x] Add PostgresClient funcs + tests

MahdiBM avatar Aug 22 '24 19:08 MahdiBM

Codecov Report

Attention: Patch coverage is 35.21127% with 92 lines in your changes missing coverage. Please review.

Project coverage is 61.01%. Comparing base (5d817be) to head (f388f5e).

Files with missing lines Patch % Lines
...es/PostgresNIO/Connection/PostgresConnection.swift 0.00% 55 Missing :warning:
Sources/PostgresNIO/Pool/PostgresClient.swift 0.00% 34 Missing :warning:
Sources/PostgresNIO/New/PSQLRowStream.swift 94.33% 3 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #504      +/-   ##
==========================================
- Coverage   61.39%   61.01%   -0.39%     
==========================================
  Files         125      125              
  Lines       10149    10291     +142     
==========================================
+ Hits         6231     6279      +48     
- Misses       3918     4012      +94     
Files with missing lines Coverage Ξ”
Sources/PostgresNIO/New/PostgresRowSequence.swift 90.38% <ΓΈ> (ΓΈ)
Sources/PostgresNIO/New/PSQLRowStream.swift 87.53% <94.33%> (+1.17%) :arrow_up:
Sources/PostgresNIO/Pool/PostgresClient.swift 0.00% <0.00%> (ΓΈ)
...es/PostgresNIO/Connection/PostgresConnection.swift 34.46% <0.00%> (-3.99%) :arrow_down:

... and 2 files with indirect coverage changes

πŸš€ New features to boost your workflow:
  • ❄ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Aug 22 '24 19:08 codecov[bot]

@fabianfett I've thought a bit more about this and possibly we might want to have another type that wraps PostgresRowSequence in the next major version at least? so we can expose more stuff in the response. Not only the metadata, but maybe even the connection properties? Or who knows what. I don't have an immediate use-case for connection properties but it looks like some lost info. Maybe someone finds a value in them although they can also be individually queried.

MahdiBM avatar Aug 27 '24 16:08 MahdiBM

I'd love this addition! I have queries that should update exactly 1 row. I'd like to check that the update was successful, but I can't check without the metadata. (These queries currently don't return the row itself.)

bridger avatar Oct 09 '24 08:10 bridger

I'm not a fan of the proposed API changes: They either get everything into memory, or they force users to consume the rows synchronously. I consider both bad options.

I honestly don't think this is a problem. We're not really taking any options away.

However I do have an alternative in mind:

To be honest this looks better, at least at the first glance. So I'd be happy to move this way.

MahdiBM avatar Dec 08 '24 11:12 MahdiBM

@MahdiBM what is the expected timeframe for this change to be included in a release ? Just wondering whether I should wait or fall back to using Connection.query in the interim ? I don't mind using a pre-release branch if there is one since we are in development still.

duncangroenewald avatar Feb 25 '25 05:02 duncangroenewald

@duncangroenewald IIRC you found a solution for now using that PostgresDatabase function that has a onMetadata? Anyway, I'm not sure about when this'll be released. I finished the PR now, @fabianfett will need to review and approve when he has time, then we'll see.

MahdiBM avatar Mar 02 '25 18:03 MahdiBM

CodeCov report is not accurate about those funcs in the first 2 listed files not having tests. For some reason even Xcode can't correctly find the new funcs' symbols.

I've added both unit and integration tests.

MahdiBM avatar Mar 02 '25 18:03 MahdiBM

@MahdiBM - OK well if there is any chance of creating a beta branch with this added let me know as I would rather use that than have to go back and simplify things later on.

duncangroenewald avatar Mar 02 '25 18:03 duncangroenewald

@duncangroenewald I took a look and this branch is up to date with main, so you could temporarily depend on this branch (repo: https://github.com/MahdiBM/postgres-nio.git, branch: mmbm-row-seq-expose-metadata) if you want. Or did you mean a "beta release"?

MahdiBM avatar Mar 02 '25 18:03 MahdiBM

thanks that branch of yours should be fine - just don't deleted it :)

I'll let you know how it goes.

duncangroenewald avatar Mar 02 '25 18:03 duncangroenewald

@MahdiBM - any plan to include this in a release any time soon ? Thanks

duncangroenewald avatar Jun 13 '25 19:06 duncangroenewald

@fabianfett can you have another look at this please? πŸ™‚

MahdiBM avatar Jun 24 '25 17:06 MahdiBM