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 to sqlx 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.
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