+
Skip to content

Conversation

Expurple
Copy link
Member

@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

@Expurple
Copy link
Member Author

Expurple commented Dec 2, 2024

@tyt2y3 @billy1624 is there any chance this can get merged? I'm still using the fork :(

Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay

@tyt2y3 tyt2y3 merged commit eb8dcde into SeaQL:master Feb 19, 2025
Copy link

🎉 Released In 1.1.6 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

hjarraya pushed a commit to sambaclab/sea-orm that referenced this pull request Apr 29, 2025
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.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载