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

Access the underlying row type of QueryResult #2265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Expurple
Copy link
Contributor

@Expurple Expurple commented Jun 20, 2024

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.

PR Info

  • Closes
  • Dependencies:
  • Dependents:

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
  • reexported sea_orm::sqlx

Bug Fixes

Breaking Changes

Changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant