Closed jharrilim closed 2 months ago
And tried to run it with cargo t --test query_tests --features sqlx-dep, but I get a bunch of compile errors saying use of undeclared crate or module sqlx
sqlx-dep is a 'transitive dependency'. You have to specify a specific backend, e.g. sqlx-postgres
and also a runtime, `runtime
I'm not sure if it would be better to return an impl Iterator for the column names, or return actual column structs with their metadata instead.
Whatever suits your need is good enough for now! Although I'd rename the method to column_names
so that we can implement the other versions in the future.
Alright, I've made the requested changes and added a test!
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 ā.
tl;dr: Add a method for retrieving column names from query results so that applications can use them alongside retrieved rows
Background
For creating some database tooling, I'd like to be able to retrieve database column names that come with the query results. This would be very dynamic because the queries are either generated at runtime from the user, or from introspection. Ideally I'd be able to get to a point where I have something like this:
so that I can display headers in a table and the rows underneath them. Not so different from the output that you'd see in
psql
.Aside
I've considered using sqlx directly, but I can't map the inner types to rust types easily https://github.com/launchbadge/sqlx/issues/1369, and that seems to be covered in sea-orm.
My current implementation is really basic. I'm not sure if it would be better to return an
impl Iterator
for the column names, or return actual column structs with their metadata instead.I wasn't too sure how to write and execute tests for this. I had initially wrote one in the
query.rs
file like:And tried to run it with
cargo t --test query_tests --features sqlx-dep
, but I get a bunch of compile errors sayinguse of undeclared crate or module
sqlx`. Maybe there's a better way?New Features
Breaking Changes