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

Problem getting query metadata from a PostgresClient query #525

Open
neilt opened this issue Nov 30, 2024 · 4 comments
Open

Problem getting query metadata from a PostgresClient query #525

neilt opened this issue Nov 30, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@neilt
Copy link

neilt commented Nov 30, 2024

I am trying to find a way to access the query metadata from a PostgresClient query. The following code fails on the return statement which should return the number of rows deleted. I cannot seem to find a workaround. Is there a way to access the query metadata.

    static func deleteFromTable(client: PostgresClient, columnValue: String, columnName: String) async throws -> Int {
        var myBindings = PostgresBindings()
        myBindings.append(PostgresData(string: tableName))
        myBindings.append(PostgresData(string: columnName))
        myBindings.append(PostgresData(string: columnValue))
        let myQuery = PostgresQuery(unsafeSQL: #"DELETE FROM $1 WHERE $2 = $3;"#,
                                    binds: myBindings)
        let rows = try await client.query(myQuery).collect()
        return rows.metadata.rows // <- fails Value of type '[PostgresRow]' has no member 'metadata'
    }

Postgres-nio 1.22.1

@MahdiBM
Copy link
Contributor

MahdiBM commented Nov 30, 2024

What do you mean by "fails"?
Do you get a compiler error or something?
If so, what exactly?

@neilt
Copy link
Author

neilt commented Nov 30, 2024

What do you mean by "fails"? Do you get a compiler error or something? If so, what exactly?

Edit the original. The error is "Value of type '[PostgresRow]' has no member 'metadata'"

@MahdiBM
Copy link
Contributor

MahdiBM commented Nov 30, 2024

Ok so that's a compiler error.

What you need is #504.
Basically, yes, PostgresNIO currently does not expose the metadata at all, in those functions.

cc @fabianfett I'd assume you're not super happy with the API design in that PR? I'm not either, but I couldn't think of any better ways. I'm open to your guidance if you have better ideas around how to expose the query metadata.

@neilt
Copy link
Author

neilt commented Nov 30, 2024

Yep, collectWithMetadata() would be what I need. Anything I can do to help this along?

@MahdiBM MahdiBM added the enhancement New feature or request label Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants