-
Notifications
You must be signed in to change notification settings - Fork 490
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: add column name to the result of query function. #3201
Conversation
add column name to the result of function query.
Signed-off-by: Jack <[email protected]>
bindings/postgres/postgres.go
Outdated
@@ -186,13 +186,21 @@ func (p *Postgres) query(ctx context.Context, sql string, args ...any) (result [ | |||
return nil, fmt.Errorf("error executing query: %w", err) | |||
} | |||
|
|||
cols := rows.FieldDescriptions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run the Go formatting tool (gofumpt
).
|
||
r := map[string]interface{}{} | ||
for i, col := range cols { | ||
r[string(col.Name)] = val[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, this is a breaking change. Currently, users expect to receive a slice, but with this, they will receive a map. This will break all existing users.
Perhaps this should be a configurable option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Infact, the query function return a json, not a map or a slice: "result, err = json.Marshal(rs)", and the json should include column name,like the query function in mysql.go: "result, err := m.jsonify(rows)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my point is: that is a breaking change. If users expect the JSON to contain an array, and you're now returning a dictionary, that will break applications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your opinion, and we expect the JSON contain a dictionary,how to make a configurable option? Can you help me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to do this via request metadata which a user would need to specify to enable your new functionality, or introduce a new operation code. You can look at the code of other bindings to see how this can be done.
@Jack397419 can you fix the linter issue, and also fix DCO? For DCO: Ensure you have a local copy of your branch by checking out the pull request locally via command line. |
ping @Jack397419 |
This change is now part of #3282 which is implemented more correctly. I'm going to close this PR. |
add column name to the result of function “query”.
Description
Please explain the changes you've made
Issue reference
We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.
Please reference the issue this PR will close: #[issue number]
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: