Problem getting query metadata from a PostgresClient query
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
What do you mean by "fails"? Do you get a compiler error or something? If so, what exactly?
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'"
Ok so that's a compiler error.
What you need is https://github.com/vapor/postgres-nio/pull/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.
Yep, collectWithMetadata() would be what I need. Anything I can do to help this along?
This is already available with Connection.query(). I need this to verify that INSERT/UPDATE statements have actually been successful and how many rows were affected.
https://github.com/vapor/postgres-nio/pull/95