How do you generalize connections from a Pool and a Transaction while being able to enter new transactions? #3618
Unanswered
insomnimus
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to abstract away common database operations in a modular fashion, meaning generic functions.
I need a "database" value that
But I also need that "database" type to include
&Pool
and&mut SqliteConnection
(or&mut Transaction
, but I can deref manually), via a trait.1 and 3 seem to be doable. I'm most having trouble with 2 because there's no trait to generalize it with, and my attempts of making one myself weren't successful.
Given those requirements, I'm unable to find a solution.
I was envisioning something similar to below (making up a trait that would encompass all that, called
Sql
; it's just to demonstrate the point):This example's a bit contrived, and I left out the bit about being able to call it with a
Pool
as well as a&mut impl Connection
/Transaction
for brevity. I'm hoping it's not hard to imagine use cases where that would be desired.So... How do we actually do this kind of thing with sqlx?
Beta Was this translation helpful? Give feedback.
All reactions