-
Notifications
You must be signed in to change notification settings - Fork 11
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
Easier integration with tests #44
Comments
Interesting ideas, and in general I'd be up for making improvements that aid testability. Could you possibly provide some example test code using the API(s) you are thinking of? That would help me understand your use-case and quickstart an exploration if I find some time. |
Sure thing, this is pretty rough, but hopefully gives you the idea. If not then please let me know and I'll flesh it out a bit more
This would work the same, but not get a connection from the pool, just use the provided one. This feels lighter, but I don't know if there's a practical difference really.
This would re-use the transaction for any This may allow for not resetting the db after each test (with a different setup function than sqlx::test). I tried to hack something together as a PoC, but I couldn't make it work. I don't know if all of this is worth the effort, but maybe with your experience you can see if this would be helpful in any way. Thanks! |
Thanks, I think I understand the goal with the 2nd one, to allow the transaction to roll back when the test finishes. I do think that's a useful technique so I'll look into supporting it at some point. I'm less sure about the 1st (as compared to, e.g., using a pool with a single connection – perhaps what I likely won't have time to look into it for a couple of weeks though. |
No worries, thanks. I’m not waiting on this as I have something that works. |
Hi, thanks for building this library, it's important and often overlooked.
I'd like to discuss if there's a way to improve the integration with tests. Using
#[sqlx::test]
you can get a connection, a pool or connection info to build your own pool.The flow will often be:
This is possible with the current library, but I wonder if it could be improved.
setup
so it's not so easy to acquire a connection to issue the queriesI wonder if there could be a couple of extra options for the state/layer:
resolve
at the end of the requestThe text was updated successfully, but these errors were encountered: