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

postgres binding: added fix for uuid and numeric datatype columns and added two new methods fetchOne and fetchAll #3282

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sridhar-shivraj
Copy link

@sridhar-shivraj sridhar-shivraj commented Dec 20, 2023

postgres binding: added fix for uuid and numeric datatype columns and added two new methods fetchOne and fetchAll

Description

Fixed the issue for uuid and numeric datatype columns, earlier uuid was coming as list of strings

Added two new methods

  1. FetchOne: returns one row as map with column names
  2. FetchAll: returns array of map with column names

Issue reference

[https://github.com//issues/1016]

Please reference the issue this PR will close: #[1016]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation / Created issue in the https://github.com/dapr/docs/ repo: dapr/docs#[issue number]

… added two new methods fetchOne and fetchAll
@sridhar-shivraj sridhar-shivraj requested review from a team as code owners December 20, 2023 11:20

// Register uuid and decimal types with pgx
poolConfig.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
pgxuuid.Register(conn.TypeMap())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe Postgres has built-in support for UUID via the google/uuid package that we use throughout Dapr. I'd rather not add another dependency here if possible

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently there is an issue with pgx for uuid and numeric columns which returns uuid or numeric columns as a array of strings #1016
You can find the details about the fix here https://github.com/jackc/pgx/wiki/UUID-Support

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather using something that is based on https://pkg.go.dev/github.com/google/uuid please - that's the package we use throughout Dapr

Comment on lines +42 to +43
fetchOneOperation bindings.OperationKind = "fetchOne"
fetchAllOperation bindings.OperationKind = "fetchAll"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between fetchOne, fetchAll, and query?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query: returns array of strings (with no column names)
fetchOne: returns map of key value pairs (with column names as key)
fetchAll: returns array of map of key value pairs (with column names as key)

for rows.Next() {
val, rowErr := rows.Values()
if rowErr != nil {
return nil, fmt.Errorf("error reading result '%v': %w", rows.Err(), rowErr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rows.Err() and rowErr should be identical per docs

Suggested change
return nil, fmt.Errorf("error reading result '%v': %w", rows.Err(), rowErr)
return nil, fmt.Errorf("error reading row: %w", rowErr)

for rows.Next() {
val, rowErr := rows.Values()
if rowErr != nil {
return nil, fmt.Errorf("error reading result '%v': %w", rows.Err(), rowErr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("error reading result '%v': %w", rows.Err(), rowErr)
return nil, fmt.Errorf("error reading row: %w", rowErr)

}

rs := make(map[string]any, 0)
for rows.Next() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since "fetchOne" is meant to fetch a single row, this method should return an error if the query returns more than one row.

Within the for loop, add a check to see if this is the 2nd iteration, and stop with an error if it is.

Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale label Feb 18, 2024
@daixiang0
Copy link
Member

ping @sridhar-shivraj

@github-actions github-actions bot removed the stale label Feb 19, 2024
Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale label Mar 20, 2024
@ItalyPaleAle
Copy link
Contributor

ping @sridhar-shivraj

@github-actions github-actions bot removed the stale label Mar 20, 2024
@yaron2
Copy link
Member

yaron2 commented Apr 18, 2024

@sridhar-shivraj are you planning to work on this PR further?

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

Successfully merging this pull request may close these issues.

None yet

4 participants