Access the underlying row type of QueryResult
#2265
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have a use case with dynamic queries, similar to what's described in #2148. Using an existing SeaORM connection (switching to another library is not an option), I need to execute dynamic queries and then process the result by inspecting the returned columns, their types, type names, values in rows...
At the moment, QueryResult doesn't provide all necessary info to do that. sqlx::Row trait does, but it's not implemented for QueryResult. In theory, I could've tried to implement it. But I couldn't immediately tell if it's possible or how long it's going to take, given that MockRow and ProxyRow don't implement it either. And I don't actually care about those, because I only ever use real Postgres!
So I went with an approach that's quick and guaranteed to provide all necessary info. I simply added direct access to the underlying sqlx::PgRow which already implements sqlx::Row. I also reexported
sea_orm::sqlx
in order to have guaranteed access tosqlx
types at correct versions and feature flags. This worked really well and I already depend on my fork of 0.12.15 in my project.I'd like to upstream it. To make a better contribution, here I also added equivalent methods for all other databases.
Tests don't seem to be necessary here. These accessor methods are trivial and I'm not even sure how to manually construct a
QueryResult
in a public doctest.PR Info
New Features
QueryResult::try_as_mysql_row
QueryResult::try_as_pg_row
QueryResult::try_as_sqlite_row
QueryResult::try_as_mock_row
QueryResult::try_as_proxy_row
sea_orm::sqlx
Bug Fixes
Breaking Changes
Changes