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

Providing a TypedRow<T> type that supports lifetimes with a macro #2661

Open
DrSloth opened this issue Jul 27, 2023 · 0 comments
Open

Providing a TypedRow<T> type that supports lifetimes with a macro #2661

DrSloth opened this issue Jul 27, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@DrSloth
Copy link

DrSloth commented Jul 27, 2023

Is your feature request related to a problem? Please describe.
Currently there is no way (as far as i have found) to use the sqlx macros with data with lifetimes. This means when iterating a lot of Rows it can be a significant benefit to use the query function and decode from the Row without additional allocation. While using the functions we loose the benefit of the query being checked at compile time.

Describe the solution you'd like
Optimally there would be something like a TypedRow<T> wrapper which internally stores a Row and and has a function like decode or get to actually get the data which might contain lifetimes bounded by the lifetime of the Row.

Describe alternatives you've considered
One simple but very non optimal solutions would be to duplicate the query inside something like an inner function inside a macro, but this would either require using the FromRow implementation which would lookup by name and not by index or by hand writing a decoding functions which uses the correct order of indices which is tedious and error prone.
This functionality could probably be implemented in another crate but i think that would require a lot of duplication from what is already implemented in here.

Additional context
I would love to work on this feature and implement it to improve sqlx and provide this functionality which i, and maybe others also, could benefit from. I probably would need some minor guidance for that but i would love to help.

Thanks for your time :)

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

No branches or pull requests

1 participant